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

A script that is suppose to drop a part in the players position when the die not working?

This is my code, I cant figure out why it doesnt work. I get no errors, and it has never worked.

-- Variables:
	local Player = game.Players.LocalPlayer
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	local Clone = game.Lighting.Button:Clone()
	local Torso = Character:WaitForChild("HumanoidRootPart")
	-- Main code:
	Humanoid.Health.Changed:Connect(function(health)
	    if health == Humanoid.Health then
	        if Humanoid.Health < 1 then
		Clone.Parent = workspace
		Clone.Position = CFrame.new(Torso.Cframe)
		wait(1)
		Clone.Anchored = true
				

	        end
	    end
		end)

2 answers

-- Variables:
    local Player = game:GetService("Players").LocalPlayer
    local Character = Player.Character
    local Humanoid = Character:WaitForChild("Humanoid")
    local Clone = game:GetService("Lightning").Button:Clone()
    local Torso = Character:WaitForChild("HumanoidRootPart")
    -- Main code:
	    Humanoid.Died:Connect(function()
        Clone.Parent = workspace
        Clone.Position = CFrame.new(Torso.Cframe)
        wait(1)
        Clone.Anchored = true
        end)

if it doesnt work tell me

2 comments

0

Doesnt work, this is suppose to be in a Local script right?

0

yeah and if you want it to replicate just tell me :)

Try this if it does not work then tell me. Health is a property which cannot have events. You said Humanoid.Health.Changed but it needs to be Humanoid.HealthChanged


-- Variables:
    local Player = game.Players.LocalPlayer
    local Character = Player.Character
    local Humanoid = Character:WaitForChild("Humanoid")
    local Clone = game.Lighting.Button:Clone()
    local Torso = Character:WaitForChild("HumanoidRootPart")
    -- Main code:
    Humanoid.HealthChanged:Connect(function(health)
        
            if Humanoid.Health < 1 then
        Clone.Parent = workspace
        Clone.Position = CFrame.new(Torso.Cframe)
        wait(1)
        Clone.Anchored = true


            end
    
        end)

3 comments

0

Didnt work, sorry I didnt check for a while.

0

Wait a minute, there is a line saying (if health == Humanoid.Health then). Fun Fact this will almost never be true only if it is divisible by two. I edited the script and if you dont see the new script wait for couple minutes because of lag.

0

Also I updated my answer, please copy it and see if it works, it doesn't work because of the if statement logic.

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