Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I put players into teams?

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)

1 comment

0

Why are you using Lua in a way like Javascript?

2 answers

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.

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.

1 comment

0

Sorry, I didn't explain, :( Kind of lazy as of now.

This discussion is preserved as it was. New answers, comments, and votes are closed.