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

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

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

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

2 comments

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.

0

Any output?

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