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

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

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)

4 comments

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

0

wut, what is the difference between the connect and Connect?

0

How would you share variables among different scripts? That's the main point, the respawn script oddly still works despite the deprecated items.

0

@Kiriyato connect is deprecated. Connect should be used as it is not.

1 answer

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 comment

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.

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