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

Why won't this work?

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

✓ Accepted answer

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

2 comments

0

Thanks that worked

0

No prob. Glad I could help :P

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