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

How do I fix my death event script? [Elaboration]

So basically the function of this script is supposed to be this:

Once a certain player in the game dies, a block is destroyed. [In this case myself, PoInareffe] I don't know which part of the script is broken, though I have tried to test each part of the script alone with a 'print' though it shows no real results.

I am also getting an error at the "victim.hum.Health == 0 then" line which is saying "Syntax error: Expected identifier when parsing expression, got 'then'". I am not sure what to make of this except the fact that the 'then' is probably not supposed to be there though I do not know what to replace it with. Any help with fixing this would be appreciated!

local victim = game.Players:FindFirstChild("PoInareffe")
local char = victim.Character
local hum = char.Humanoid
local lay = game.Workspace.PlaceDie.Lay.Part

victim.hum.Health == 0 then
	lay:Destroy()
end

I am relatively new to scripting so excuse my messy script.

1 comment

0

Oh I forgot to mention that this is a normal Script inside of the Workspace.

1 answer

✓ Accepted answer

The char variable is not really needed, since the victim is the Character itself. You also forgot the if at line 6 or you may have removed it unaware.

local victim = game.Players:FindFirstChild("PoInareffe")
local hum = victim.Humanoid -- Removed char variable, changed 'char.Humanoid' to 'victim.Humanoid'
local lay = game.Workspace.PlaceDie.Lay.Part

-- Added 'if', removed 'victim'
if hum.Health == 0 then
    lay:Destroy()
end

Also it will not work since this script will only run once, you are better off using Humanoid.Died

hum.Died:Connect(function() 
	lay:Destroy()
end)

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