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

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

Asked by 5 years ago

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)
0
You might want to wait for the Character. songboy50 77 — 5y
0
Also when updating a Gui you always want to update the PlayerGui instead of the StarterGui by fade = player.PlayerGui.ScreenGui.Frame.BackgroundTransparency songboy50 77 — 5y
0
also, learn the difference between references and values theking48989987 2147 — 5y
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 Fad99 286 — 5y

2 answers

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

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)
Ad
Log in to vote
0
Answered by
Despayr 505 Moderation Voter
5 years ago

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)

Answer this question