Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 10 years ago

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




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! BlueTaslem 18071 — 10y

1 answer

Log in to vote
-1
Answered by 10 years ago
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)
0
It doesnt work :? Timster111 25 — 10y
0
I fixed it tho :D Timster111 25 — 10y
Ad

Answer this question