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

Why won't this work?

Asked by
duckyo01 120
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So what I want this script to do is that when they click the button their right arm comes off. But for some reason it doesn't' delete the arm.

local button = script.Parent
function onClick(part)
    local Player = script.Parent:FindFirstChild("Humanoid")
    if Player then
        local darm = button:FindFirstChild('Right Arm')
        darm.Remove

    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

Please help me.

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

Your problem is that you're trying to get the player incorrectly, and you're not destroying it properly. For ClickDetectors, the argument that the function provides, is the player who clicked. So all we need to do, is set that and use it.


The code should look like this:

function onClick(Player)
    --Code
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

So now that we have that set up, we just need to get the players character, then remove the arm.

function onClick(Player)
    if Player then
        local darm = Player.Character:FindFirstChild('Right Arm')
        darm:Destroy() --You should use the :Destroy() instead of :remove(). Remove is disambiguate.
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

So now your script should work correctly. If you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P

-Dyler3

0
Thanks that worked duckyo01 120 — 9y
0
No prob. Glad I could help :P dyler3 1510 — 9y
Ad

Answer this question