I can't change team when touched a part my code:
local player = game.Players.LocalPlayer
script.Parent.Touched:Connect(function()
player.TeamColor = BrickColor.new("Bright blue")
end)
I can't change team when touched a part my code:
local player = game.Players.LocalPlayer
script.Parent.Touched:Connect(function()
player.TeamColor = BrickColor.new("Bright blue")
end)
If the script is not a local script, Put this in a server script (Regular script) because you can take a LocalPlayer only from a local script.
If the script is a local script, Try using this script:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- If the thing who touched the part is a player
local player = game.Players:FindFirstChild("hit.Parent.Name") -- Get the player
player.TeamColor = BrickColor.new("Bright blue")
end
end)
If any of what I said isn't working, Try using RemoteEvents:
http://robloxdev.com/api-reference/event/RemoteEvent/OnServerEvent or https://wiki.roblox.com/index.php?title=API:Class/RemoteEvent
Video about RemoteEvents and how they work:
https://www.youtube.com/watch?v=4Dc_bri9mjs
If this helped you please accept my answer that would be really appreciated, Plus we both make reputation out of that.
-MajinBluee
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Use :GetPlayerFromCharacter(). Line 3 would only look for a player named "hit.Parent.Name".
Do not remind users to accept your answer, as it is nature for them to accept it. You're just being greedy.