i dont want to use spawnlocation
plr = game.Players.LocalPlayer
script.Parent.Touched:Connect(function(Hit)
plr.Teamcolor = BrickColor.new("Really red")
end)
i tested it with script and local script but not working
i dont want to use spawnlocation
plr = game.Players.LocalPlayer
script.Parent.Touched:Connect(function(Hit)
plr.Teamcolor = BrickColor.new("Really red")
end)
i tested it with script and local script but not working
You can do this with a server script. All you need to do is add a server script and then write the following code:
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.TeamColor = BrickColor.new("Team color here")
player:LoadCharacter()
end
end)
Explaining the code:
game.Players:GetPlayerFromCharacter(hit.Parent) returns the player from the argument passed. If the argument is the character model, the player will be returned. If it is not a character model, this function returns nil.
Since it can return nil, you check that the player exists. If it does exist, the TeamColor property is changed to whatever color you specify, them the character is reloaded.
There are 3 comments. That's not too many lol and it's not my fault.
The comments are way too long, making this code unreadable. You do realise you can post explanations outside of the code, or even shorten them?
Do you go on people's questions that are answered to down vote someone for explaining? You're going to down vote someone if they don't explain and you're going to down vote someone if they do explain?
Readability is important. Always take it into consideration. I will edit this answer myself if you don't
Really. You're the only one who ever complains about "too many comments"
Go ahead and edit it yourself. I don't care
thank you but can you tell me what this script do? local player = game.Players:GetPlayerFromCharacter(hit.Parent)
I just explained it for you and made the code cleaner because I actually care, unlike someone here
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
LocalScripts can't run in the Workspace. Use a server script and check for a player associated with Hit.Parent.
plr = game.Players.LocalPlayer game.Workspace.Part.Touched:Connect(function(Hit) Hit.Parent.Teamcolor = BrickColor.new("Really red") end) i tried this but not working