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?
01 | game.Players.LocalPlayer.Character:WaitForChild( "Humanoid" ).Died:connect( function () |
02 | script.Parent.DarkSoulsNoise:Play() |
03 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
04 | wait( 0.01 ) |
05 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
06 | wait( 0.01 ) |
07 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
08 | wait( 0.01 ) |
09 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
10 | wait( 0.01 ) |
11 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
12 | wait( 0.5 ) |
13 | script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1 |
14 | wait( 0.08 ) |
15 | script.Parent.Deadline.YouAreDie.TextTransparency = script.Parent.Deadline.YouAreDie.TextTransparency - 0.1 |
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
01 | local player = game.Players.LocalPlayer |
02 | local char = Player.Character |
03 |
04 | while char.Parent = = nil do |
05 | char.AncestryChanged:wait() |
06 | end |
07 |
08 | char:WaitForChild( "Humanoid" ).Died:Connect( function () |
09 | script.Parent.DarkSoulsNoise:Play() |
10 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
11 | wait( 0.01 ) |
12 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
13 | wait( 0.01 ) |
14 | script.Parent.Deadline.BackgroundTransparency = script.Parent.Deadline.BackgroundTransparency - 0.2 |
15 | wait( 0.01 ) |
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.
01 | local plr = game:GetService 'Players' .LocalPlayer |
02 | local char = plr.Character or plr.CharacterAdded:Wait() |
03 |
04 | char.Humanoid.Died:Connect( function () |
05 | for i = 1 , 0 , -. 2 do |
06 | script.Parent.Deadline.BackgroundTransparency = i |
07 | wait() |
08 | end |
09 |
10 | for i = 1 , 0 , -. 1 do |
11 | script.Parent.Deadline.YouAreDie.TextTransparency = i |
12 | wait() |
13 | end |
14 | end ) |