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

Clone() / for loop.... Please Help!?

I want to clone the Click Detector into every players torso when they are in the game! Please help! Im still learning for loops and I cant find a good explanation so I tried some youtube videos and this doesnt work Please Help!

	for i,v in pairs(game.Players:GetPlayers()) do
		name = v.Name
		check = game.Workspace:FindFirstChild(name)
		if check then
		c = game.ServerStorage.ClickDetector:Clone()
		c.Parent = v.Character.Torso				
		end
	end
		

		
		

1 comment

0

Your use of check is long-winded. You could condense that all into one line: if workspace:FindFirstChild(v.Name) then Of course, it would make more sense to actually check v.Character. Additionally, you forget to check that the Torso exists!

1 answer

✓ Accepted answer
game.Players.PlayerAdded:connect(function(p) -- triggers when a player joins the server. Also gives me the player (p).
p.CharacterAdded:connect(function(c) -- triggers when the character is created or respawned. gives me the character(char)
local cloned = game.ServerStorage.ClickDetector:Clone()
cloned.Parent = char.Torso

end) -- there is a ) at the end because the function and connector line is tied together. This is a cool trick to learn.

end)

2 comments

0

It doesnt work :?

0

I fixed it tho :D

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