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

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

Asked by 2 years ago

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.

0
Oh I forgot to mention that this is a normal Script inside of the Workspace. TheJacksterYT 19 — 2y

1 answer

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

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)
Ad

Answer this question