Hello, i am having a problem with this script, it is a script to pick up a flag and lower a value, but that is not a problem, it is a function to stop the same team from picking up their own flag. It always prints invalid (that i have put to check), even if i am in the opposite team.
Here's the code:
function checkplayer(hit) local player = players:GetPlayerFromCharacter(hit.Parent) local playername = hit.Parent.Name local human = hit.Parent:FindFirstChild("Humanoid") if human then if not players[playername].TeamColor == BrickColor.new("Bright blue") then ontouchorremove() print("valid") else print("invalid") end end end script.Parent.Touched:Connect(checkplayer)
I have recently updated the script, no worry's. I changed the 6th line to a if then statement instead than a if not then statement. Also, i had to add a argument for calling my other function.
function checkplayer(part) local playername = part.Parent.Name local human = part.Parent:FindFirstChild("Humanoid") if players[playername].TeamColor == BrickColor.new("Bright red") then ontouchorremove(part) print("valid") else print("invalid") end end script.Parent.Touched:Connect(checkplayer)