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

How would I make this TeamColor script not be run locally in a regular script?

for i,v in pairs(model.PlayersTouching:GetChildren()) do
	local player = game.Players.LocalPlayer
		player.TeamColor = BrickColor.new("Sea green")
end

How would I make this script in a regular script not be run locally? The PlayersTouching is a table model inside a model that creates a list inside of itself of all the players touching the model which works perfectly fine. But I need all the players in that table to get their team changed and I've been struggling to figure out how to not do it locally. Help?

2 comments

0

LocalPlayer can only be accessed by a LocalScript. Note that a LocalScript should only ever be a descendant of a player and never anything else. It just won't work.

0

If I helped you out, please accept my answer.

1 answer

✓ Accepted answer

If the table is a list of the player objects then just do v.TeamColor = BrickColor.new("Sea green") because v will be each player already because of the loop. If it is a list of the players names just do:

local players = game:GetService("Players")-- the recommended method for getting services like players 
for i,v in pairs(model.PlayersTouching:GetChildren()) do
	local player = players:FindFirstChild(v) -- returns the player object from players after finding the player with v as their name
end

If the list is a list of the parts touching the model then do this:

local players = game:GetService("Players")
for i,v in pairs(model.PlayersTouching:GetChildren()) do
	if v.Parent:FindFirstChild("Humanoid") then -- if it is a players body part touching then
		players:GetPlayerFromCharacter(v.Parent)
	end
end

Hope this helps and have a great day scripting!

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