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

I wrote a script to change the team of the player but it's not working?

Asked by 4 years ago

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

0
LocalScripts can't run in the Workspace. Use a server script and check for a player associated with Hit.Parent. DeceptiveCaster 3761 — 4y
0
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 tnt54868726 3 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited by User#24403 4 years ago

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.

0
There are 3 comments. That's not too many lol and it's not my fault. namespace25 594 — 4y
0
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? User#24403 69 — 4y
0
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? namespace25 594 — 4y
0
Readability is important. Always take it into consideration. I will edit this answer myself if you don't User#24403 69 — 4y
View all comments (4 more)
0
Really. You're the only one who ever complains about "too many comments" namespace25 594 — 4y
0
Go ahead and edit it yourself. I don't care namespace25 594 — 4y
0
thank you but can you tell me what this script do? local player = game.Players:GetPlayerFromCharacter(hit.Parent) tnt54868726 3 — 4y
0
I just explained it for you and made the code cleaner because I actually care, unlike someone here User#24403 69 — 4y
Ad

Answer this question