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

I have a localscript that is supposed to fire when the humanoid dies, yet it does not?

i have this script. its a localscript located inside of replicatedfirst. its supposed to make a screengui become apparent when the localplayer dies, yet it does nothing. nothing in the console shows up.

wait(1)
local player = game.Players.LocalPlayer
local char = player.Charcter
local humanoid = char.Humanoid
local fade = game.StarterGui.ScreenGui.Frame.BackgroundTransparency
humanoid.Died:Connect(function()
fade = 0
end)

4 comments

0

You might want to wait for the Character.

0

Also when updating a Gui you always want to update the PlayerGui instead of the StarterGui by fade = player.PlayerGui.ScreenGui.Frame.BackgroundTransparency

0

also, learn the difference between references and values

0

id recommend what songboy50 is saying, try to put the local script in starter gui, it will make things easier, and remember a local script is always the descendant of a player

2 answers

The issue I found when testing this was that you created a local variable which directed to a property of an instance, not only that you you are changing the Frame in the StarterGui and not the PlayerGui.

you wrote

local fade = game.StarterGui.ScreenGui.Frame.BackgroundTransparency
humanoid.Died:Connect(function()
    fade = 0
end)

instead it should be:

local fade = player:WaitForChild("PlayerGui").ScreenGui.Frame.BackgroundTransparency
humanoid.Died:Connect(function()
    fade.BackgroundTransparency = 0
end)

By the way, you also misspelled Character in local char = player.Charcter

so this should work

wait(1)
local player = game.Players.LocalPlayer
local char = player.Character
local humanoid = char.Humanoid
local fade = player:WaitForChild("PlayerGui").ScreenGui.Frame.BackgroundTransparency
humanoid.Died:Connect(function()
    fade.BackgroundTransparency = 0
end)

1- You are setting the 'fade' variable to the value of backgroundtransparency. 2- You mispelled Character on line 3 3- You need to change the gui inside of the PlayerGui, not the StarterGui

this can be fixed by setting said variable to the frame instead.

local Server = game:GetService("Players")
local Player = Server.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()

local fade = Player.PlayerGui.ScreenGui.Frame
local function HumanoidDied()
	fade.BackgroundTransparency = 0
end

Character:WaitForChild("Humanoid").Died:Connect(HumanoidDied)

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