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.
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.
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
Thank you! Your explanation was very clear
Your welcome! Always happy to help!
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Why the ((local cd)) has a ClickDetector object after new?