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

How would you make a gui change pictures when an NPC dies?

Asked by
tran18 -5
5 years ago
Edited 5 years ago

I've tried to do this by using _G variable in a respawn script in order to signal when the NPC died, but this didn't work on the live game.

The respawn script was a regular script and the gui script was a local script in the starter gui of a player.

Could someone give a quick example? The basic respawn script is below if that helps, I'm pretty sure it has all the necessary parts.

target = script.Parent:Clone()

function Dead()
    local respawn=target:Clone()
    respawn.Parent=script.Parent.Parent
    respawn:MakeJoints()
    script.Parent:Destroy()
end
script.Parent.Humanoid.Died:Connect(Dead)
0
Don't use _G, and you're using too many deprecated items. clone, connect,remove, and makeJoints are deprecated, use Clone, Connect, Destroy, and MakeJoints User#19524 175 — 5y
0
wut, what is the difference between the connect and Connect? Kiriyato 15 — 5y
0
How would you share variables among different scripts? That's the main point, the respawn script oddly still works despite the deprecated items. tran18 -5 — 5y
0
@Kiriyato connect is deprecated. Connect should be used as it is not. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

So you'd need to create a RemoteEvent to be able to pass the death event to the client.

--Warning: Untested code! I'm typing right into this SH answer!
local event     = game.ReplicatedStorage.RemoteEvent
local target    = script.Parent:Clone()

function Dead()
    local respawn   = target:Clone()
    respawn.Parent  = script.Parent.Parent
    respawn:MakeJoints()
    script.Parent:Destroy()
    event:FireAllClients()
end
script.Parent.Humanoid.Died:Connect(Dead)

This will now fire the event to all the players that the Humanoid died! Now, we need to handle that on the client!

local event = game.ReplicatedStorage.RemoteEvent

event.OnClientEvent:Connect(function()
    print("Humaoid died!")
    --Change the GUI
end)

Please remember to upvote if this helps, and accept this answer if it works!

1
Don't remind users to accept your answer, or upvote it. It is nature for the asker to accept the answer. It's scummy. User#19524 175 — 5y
Ad

Answer this question