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

I have a script that removes a limb when a part is touched but it doesn't work. Any help?

Here is the script:

script.Parent.Touched:Connect(function()
	game.Players.LocalPlayer["Right Leg"].Parent = nil
end)

Any small info will help!

2 comments

0

you cannot use local player in a script

0

Instead of using .Parent you use : Destroy ()

1 answer

✓ Accepted answer

Welp, game.Players.LocalPlayer is not the player's Character in workspace, it is the player him or herself. So I suggest you use a ServerScript instead of a LocalScript.

Script will look like this:

local Touched = false -- A "debounce"

script.Parent.Touched:Connect(function(Hit)
	if Touched == false then
		if Hit.Parent:FindFirstChild("Right Leg") then -- Add this so it doesn't throw an error if Right Leg doesn't exist
			Hit.Parent:WaitForChild("Right Leg"):Destroy()
			-- Using :Destroy() may give an error so you may want to do it this way(Remove the "--" if :Destroy() gives an error):
			-- local Debris = game:GetService("Debris")
			-- Debris:AddItem(Hit.Parent["Right Leg"])
			wait(0.5)
			if Hit.Parent then -- Check if the player is still touching the part and if the player is, their other limb will be destroyed
				if Hit.Parent:FindFirstChild("Left Leg") then
					print("Player Is Still Touching The Part :/")
					Hit.Parent:WaitForChild("Left Leg"):Destroy() -- Feel free to change "Left Leg" to other parts of the player's character
		   		end
			 end
			Touched = false
		end
	end
end)

2 comments

0

Thanks! Could i do it so every 0.5 second they are on there they lose another limb? Would i have to add debounce?

0

I added a few lines which you can try, I'm not sure if it will work tho but you can try and see if it works

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