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

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

Asked by 4 years ago

Here is the script:

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

Any small info will help!

0
you cannot use local player in a script User#5423 17 — 4y
0
Instead of using `.Parent` you use `: Destroy ()` Nguyenlegiahung 1091 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
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? Spo_tted 15 — 4y
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 guest_20I8 266 — 4y
Ad

Answer this question