Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I access a player's model?

game.Players.PlayerAdded:Connect(function(plr)
	local cd = Instance.new("ClickDetector")
	cd.Parent = plr.Character:FindFirstChild("Head")
end)

I'm not sure what I'm doing wrong here as cd isn't spawning.

1 comment

0

Why the ((local cd)) has a ClickDetector object after new?

1 answer

✓ Accepted answer

The code is correct but there is one thing that you need to fix. You need to wait for the player's character or it won't get the character and the script will break.

game.Players.PlayerAdded:Connect(function(plr)
	
	local char = plr.Character or plr.CharacterAdded:Wait() --//You will wait for their character to be added if not already.

    local cd = Instance.new("ClickDetector")
    cd.Parent = char:FindFirstChild("Head")
end)

Then after the character has been added you can find the child named Head

2 comments

0

Thank you! Your explanation was very clear

0

Your welcome! Always happy to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.