I'm making a Terminal and you have to touch a part to activate it. I know why my code isn't working - It's because 'playername' isn't a child of Players. What I am trying to do is make the part that touched the capture point be put into a string and the value of the string is what is searches for in 'game.Players'. There is a String inside the parent of the script that the name appears in when you step on it.
cap = script.Parent playername = script.Parent.PlayerName playersname = playername.Value while true do cap.Touched:connect(function(player) script.Parent.PlayerName.Value = player.Parent.Name local Touchy = game.Players.playersname if Touchy.TeamColor == BrickColor.new("Bright red") then print "Raider" end end) wait(0.5) end
Please help.
cap = script.Parent playername = script.Parent.PlayerName -- no while here, due to how events work cap.Touched:connect(function(player) playername.Value = player.Name local Touchy = game.Players:findFirstChild(playername.Value) -- use the FindFirstChild method if not Touchy then print('No player found') return end if Touchy.TeamColor == BrickColor.new("Bright red") then print "Raider" end end)
This having been said, you don't need a stringValue for that: just use
cap = script.Parent playername = script.Parent.PlayerName cap.Touched:connect(function(player) if player == BrickColor.new("Bright red") then print "Raider" end end)
game.Players["Owenrules12"]