小组团队更改脚本当前有效吗?

时间:2018-10-14 20:08:24

标签: roblox

您是否需要在特定组中更改roblox工作团队的GUI才能更改团队?

1 个答案:

答案 0 :(得分:1)

您好,我已经花了20分钟为您编写一个团队变更GUI的代码,请按照以下步骤操作。 (这对FilteringEnabled友好)

步骤1 :将LocalScript插入StarterGui

步骤2 ,从下面的LocalScript复制内容并将其粘贴到您的LocalScript

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

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


ServerScript

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)

LocalScript

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的前几行!