So heres my script.
function onClicked(player) local nam = player.Name if game.Players.nam == true then game.Workspace:ClearAllChildren() end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
What I'm trying to do is find out if the clickers name, then cross examine it from the players list to make sure they're a player. How would I do this?
You can say:
function onClicked(player) local nam = player.Name local found = game.Players:FindFirstChild(nam) if found then game.Workspace:ClearAllChildren() end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
What we're doing here is that we're assigning a variable called "found" to the player's name in the game. We use FindFirstChild
to find a child named "nam" in game.Players
. If the player's name is not found, then the variable will be set to nil
.
We check if it has been found by seeing if the variable is not nil:
if found then
This should work, however, you don't really need to be checking if a player exists because a player is automatically added to game.Players
.