我如何在roblox中创建工作团队变更者GUI?

时间:2018-09-17 20:37:42

标签: roblox

我相信,在2018年的Roblox交换编码平台中,大多数脚本都可以幸免,但是我今年未能为自己找到一个工作团队变更者,该团队变更者在单击时会更改您的团队,具体取决于您是否属于certian组。我的脚本编写者说它可以在Studio中工作,但游戏中会弹出一个错误消息,内容为“ TeamColor不是PlayerGui的有效成员 堆叠开始 脚本“ Players.Benyal.PlayerGui.Starter GUI.TeamGui.Frame.Research and Development.LocalScript”,第8行 堆叠结束” 我的密码学家尝试了许多不同的方法,但它行不通!有什么隔eg吗?

1 个答案:

答案 0 :(得分:0)

此解决方案使用两个脚本(一个LocalScript和一个脚本),请按照以下步骤制作团队更改GUI!

local teams = game:GetService("Teams")
local settings = {
    ["GUIHeight"] = 30, --put in a number over 20, or 100 if you want it to fill the screen
    ["GUIWidth"] = 40, --put in a number over 20, or 100 if you want it to fill the screen
    ["GUIColor"] = Color3.fromRGB(240,240,240), --color of the team changer gui

    ["TitleText"] = "Team Changer", --title text in the gui
    ["TitleFont"] = "ArialBold", --font of title
}

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.PlayerGui
local plr = game.Players.LocalPlayer

local teamGUI = Instance.new("ScreenGui",plr.PlayerGui)
local frame = Instance.new("Frame",teamGUI)
frame.AnchorPoint,frame.Size,frame.Position,frame.BackgroundColor3 = Vector2.new(0.5,0.5),UDim2.new(settings.GUIWidth/100,0,settings.GUIHeight/100,0),UDim2.new(0.5,0,0.5,0),settings.GUIColor

local title = Instance.new("TextLabel",frame)
title.Text,title.Font,title.Size,title.TextScaled,title.BackgroundTransparency = settings.TitleText,settings.TitleFont,UDim2.new(1,0,0.15,0),true,0.5

local closebutton = Instance.new("TextButton",title)
closebutton.Size,closebutton.Position,closebutton.BackgroundColor3,closebutton.Text = UDim2.new(0.1,0,1,0),UDim2.new(0.9,0,0,0),Color3.fromRGB(255,155,155),"Close"

local list = Instance.new("ScrollingFrame",frame)
list.Size,list.Position,list.BackgroundTransparency = UDim2.new(1,0,0.85,0),UDim2.new(0,0,0.15,0),1

local UILayout = Instance.new("UIListLayout",list)

local serverTeamHandler = game.ReplicatedStorage:WaitForChild("teamChanger")
local getTeams = teams:GetChildren() --this part checks if you have teams in your game (you need to have put the teams in your game already)
for i,v in pairs(getTeams) do
    print("[Team " .. i .. " found]: " .. v:GetFullName())
    local teamButton = Instance.new("TextButton",list)
    teamButton.BackgroundColor3 = v.TeamColor.Color
    teamButton.Size = UDim2.new(1,0,0,40)

    teamButton.Text,teamButton.TextColor3,teamButton.TextStrokeTransparency,teamButton.TextScaled = v.Name,Color3.fromRGB(255,255,255),0.7,true
    teamButton.MouseButton1Down:connect(function()
        print("You changed teams. You are now in: " .. v.Name)
        serverTeamHandler:InvokeServer(v)
    end)
end

closebutton.MouseButton1Click:connect(function()
    frame:TweenPosition(UDim2.new(0.5,0,2,0),"Out","Quad",0.5)
    local returnButton = Instance.new("TextButton",teamGUI)
    returnButton.Size,returnButton.Position,returnButton.Text,returnButton.TextScaled = UDim2.new(0,200,0,50),UDim2.new(0.5,-100,1,-50),"Open Team Changer",true
    returnButton.MouseButton1Down:connect(function()
        returnButton:Destroy()
        frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Elastic",1,true)
    end)
end)

步骤1 :将LocalScript插入StarterGui

步骤2 复制上面的内容并将其粘贴到此LocalScript

步骤3 将脚本插入Workspace或ServerScriptService(您的选择)

步骤4 复制下面的内容并将其粘贴到脚本中

local teamChanger = Instance.new("RemoteFunction",game.ReplicatedStorage)
teamChanger.Name = "teamChanger"

local function changeTeam(client,team)
    print(client.Name .. "changed teams: now in" .. team.Name)
    client.Team = team
end

teamChanger.OnServerInvoke = changeTeam

如果您正确执行了这些步骤,那么您现在应该有了一个可以在游戏中更改GUI的工作团队!,只要您已经在游戏中插入了Teams,它就可以工作。还可以自定义LocalScript的前几行!