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

Need help with localplayer and Player. How do I do this?

local rep = game:GetService("ReplicatedStorage")
local team = game.Players.LocalPlayer.Team
local bigfoot = game.Teams.Bigfoot
local player = game.Players.LocalPlayer
local bigfootmodel = game.ReplicatedStorage.Bigfoot
if team == bigfoot then
	bigfootmodel.Head.Mesh:Clone() .Parent = game.Players.LocalPlayer.Character
end

do i do localplayer to go inside of the person who is in the bigfoot team?

1 answer

✓ Accepted answer

The way you reference a player depends on what kind of script you're using. Checking teams should be on a regular script though, so don't use LocalPlayer.

for i, player in pairs(game.Players:GetPlayers()) do -- In pairs loop will get table of players in the server
	local rep = game:GetService("ReplicatedStorage")
	local team = player.Team
	local bigfoot = game:GetService("Teams").BigFoot -- You have to use GetService for Teams
	local bigfootmodel = rep.Bigfoot
	if team == bigfoot then
		bigfootmodel.Head.Mesh:Clone().Parent = player.Character
	end
end

You could use a PlayerAdded event instead of an in pairs loop, but I wasn't sure if the player is automatically put into a team when they join. I used an in pairs loop just in case something needed to be done before you wanted to check their team.

(Edit: If a player is already on a team as soon as they join, I just want to make sure you know how to use PlayerAdded. If you don't need it for this, then well it could still be helpful for lots of other things. All you have to do is change the first line to this:)

game.Players.PlayerAdded:Connect(function(player)

end) -- don't include this in your first line. I just put this here to remind you that after you put your code, close with a parenthesis/bracket ) after the end.

Hope this helps!

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