Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I put players into teams?

Asked by 6 years ago

I am trying to sort players into teams on their own decision. It works but doesn't change their team in the leaderboard. This is my script for my team selector how do I change the player's leaderboard team?

wait(0.2); script.Parent.RebelsButton.MouseButton1Click:connect(function() game.Players.LocalPlayer.TeamColor = game.Teams.Rebels.TeamColor; game.Players.LocalPlayer:LoadCharacter(); game.Players.LocalPlayer.PlayerGui.TeamSelectGui:Destroy(); game.Workspace.Humanoid.name.TeamColor = "Really red" end)

script.Parent.SoldierButton.MouseButton1Click:connect(function() game.Players.LocalPlayer.TeamColor = game.Teams.Soldiers.TeamColor; game.Players.LocalPlayer:LoadCharacter(); game.Players.LocalPlayer.PlayerGui.TeamSelectGui:Destroy(); game.Workspace.Humanoid.name.TeamColor = "Dark blue" end)

0
Why are you using Lua in a way like Javascript? thesit123 509 — 6y

2 answers

Log in to vote
0
Answered by
dionant 23
6 years ago

Well, the problem is, you can't use LocalPlayer on a Script.

LocalPlayer is only usable in LocalScripts.

Basically, the script runs, but does not know which is the player it has to team.

There is no way for a ClickDetector to know who is clicking.

You should use a LocalScript that knows when a player clicks that button, etc.

Ad
Log in to vote
0
Answered by
thesit123 509 Moderation Voter
6 years ago

This is all in LocalScript

script.Parent.RebelsButton.MouseButton1Click:connect(function() 
    local plr = game.Players.LocalPlayer
    plr:WaitForChild("TeamColor").Value = game:GetService("Teams").Rebels.TeamColor
    plr:LoadCharacter()
    plr:WaitForChild("PlayerGui").TeamSelectGui:Destroy();
    -- game.Workspace.Humanoid.name.TeamColor = "Really red" end) [What are you doing exactly here?]


script.Parent.SoldierButton.MouseButton1Click:connect(function()
    local plr = game.Players.LocalPlayer
    plr:WaitForChild("TeamColor").Value = game:GetService("Teams").Soldiers.TeamColor
    plr:LoadCharacter()
    plr:WaitForChild("PlayerGui").TeamSelectGui:Destroy()
    -- game.Workspace.Humanoid.name.TeamColor = "Dark blue" end) [And here.]

Hope this kind of helps.

0
Sorry, I didn't explain, :( Kind of lazy as of now. thesit123 509 — 6y

Answer this question