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

How do I kill the player if the RootWeld is missing?

Asked by 3 years ago
Edited 3 years ago

I'm currently working on a game where the player is controlled via a custom starter character. I built the rig in a way in which the player head and arms are connected by hinges. Whenever the RootWeld is destroyed by a bomb, I want to kill the player, although my script seems to not work. I'm somewhat of a noobie when it comes to scripting, so if anyone has any advice onto how to fix this easily, it would be greatly appreciated! Also, if it helps at all, I'm running this from a LocalScript in StarterCharacterScripts.

local character = script.Parent
local root = character.Torso.RootWeld
local neck = character.Torso.Neck

repeat until true do
    if root == nil then
        character:BreakJoints()
        print("root destroyed")
    end
    wait()
end

EDIT: The RootWeld is inside the Torso. It keeps the HumanoidRootPart attached to the player.

1 answer

Log in to vote
0
Answered by
Jo1nts 134
3 years ago
Edited 3 years ago

Try replacing the root variable with character.Torso:FindFirstChild("RootWeld")

and replace if root == nil then with if not root then. Script:

local character = script.Parent
local root = character.Torso:FindFirstChild("RootWeld")
local neck = character.Torso.Neck

repeat until true do
    if not root then
        character:BreakJoints()
        print("root destroyed")
    end
    wait()
end

OR

local character = script.Parent
local root = character.Torso:FindFirstChild("RootWeld")
local neck = character.Torso.Neck

repeat until true do
    if root then return end
        character:BreakJoints()
        print("root destroyed")
    end
    wait()
end

0
After a while of experimenting with the script, I couldn't get it to work. I don't know if it's my weird faulty code or because I'm new to scripting. antaramize 15 — 3y
0
Any output? Jo1nts 134 — 3y
Ad

Answer this question