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

My Death Popup Isn't Working in The ACTUAL game?

Asked by 6 years ago

I scripted a gui to popup when you die and It doesn't popup when you're in the actual game but when you're in Studio, it works perfectly fine, please help me?

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function()
    script.Parent.DarkSoulsNoise:Play()
    script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
    wait(0.01)
    script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
    wait(0.01)
    script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
    wait(0.01)
    script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
    wait(0.01)
    script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
    wait(0.5)
    script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(1.3)
end)   
0
It says that "Attempt to Index field "Character"(a nil value) " TheMaster9245 41 — 6y
0
add this, repeat wait() until game.Players.LocalPlayer.Character before your code, it isn't perfect but should fix the script User#20388 0 — 6y
0
Why would they use a repeat until lol. Just add a CharacterAdded:Wait() User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by
Launderer 343 Moderation Voter
6 years ago

Okay so what is happening is that the Character isn't loaded yet. You have this problem in the actual game due to scripts loading before your character does. In studio it is the opposite. So what you need to do is

local player = game.Players.LocalPlayer
local char = Player.Character

while char.Parent == nil do
char.AncestryChanged:wait()
end

char:WaitForChild("Humanoid").Died:Connect(function()
script.Parent.DarkSoulsNoise:Play()
 script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
wait(0.01)
script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
wait(0.01)
script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
wait(0.01)
script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
wait(0.01)
script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2
wait(0.5)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(0.08)
script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1
wait(1.3)
end)  
0
Here is the problem with your code. Since Character is a nil value right now, your code is: nil.AncestryChanged:Wait() and while nil.Parent == nil do User#19524 175 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

This is because the scripts load in before the character is loaded. Just add this to your script. Also, switch to :Connect() as ROLOX may be removing :connect() soon.

Also instead of manually subtracting 0.2 from the transparency, use a for loop.

local plr = game:GetService'Players'.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

char.Humanoid.Died:Connect(function()
    for i = 1, 0, -.2 do
        script.Parent.Deadline.BackgroundTransparency = i
        wait()
    end

    for i = 1, 0, -.1 do
        script.Parent.Deadline.YouAreDie.TextTransparency = i
        wait()
    end
end)

Answer this question