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

Why does this script makes the death time longer?

Asked by 5 years ago

I'm trying to make an on death GUI and when I die it works fine, It says how much time you wait to spawn (5 seconds) but when it gets to 1 it waits a couple seconds more and then it disappears. I tried so many ways to change it and it doesn't work. Please help me, I would really appreciate it if you do.

Script 1:

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function()
    script.Parent.Visible = true
end)

Script 2:

while true do
    wait(0.1)

    if script.Parent.Parent.Visible == true then
        script.Parent.Text = "Spawning you in: 5 Seconds."

        wait(1)

        script.Parent.Text = "Spawning you in: 4 Seconds."

        wait(1)

        script.Parent.Text = "Spawning you in: 3 Seconds."

        wait(1)

        script.Parent.Text = "Spawning you in: 2 Seconds."

        wait(1)

        script.Parent.Text = "Spawning you in: 1 Seconds."

        while true do
            wait(0.1)

            if game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Health ~= 0 then
                script.Parent.Parent.Visible = false
            end
        end
    end
end

(The if part is kinda glitched)

Thanks, MajinBluee

0
Try taking out the second while true do and see if that fixes it? TiredMelon 405 — 5y
0
What do you mean by that? MajinBluee 80 — 5y
0
Thanks bro! MajinBluee 80 — 5y
0
To make this more compact, you might consider putting a for loop with a wait of 1 instead of manually putting 5 4 3 2 1. You can also customize how long it waits too. Pixelated_MC 33 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

A devforum post was made about customizable reset logic. https://devforum.roblox.com/t/customizable-reset-button-logic/30463

It involves making a custom callback for the reset. You then could use that to maybe fire some remote event called RespawnClient() since :LoadCharacter()(http://wiki.roblox.com/index.php?title=API:Class/Player/LoadCharacter) can only be used on the server

The code for such logic would work something like this.

Client Side:

local respawnPlayer = game:GetService("ReplicatedStorage"):WaitForChild("RespawnPlayer")
local resetCallBackEvent = Instance.new("BindableEvent")
local untilRespawn = 10 

local function resetCallback()
    wait(untilRespawn)
    respawnPlayer:FireServer()
end

resetCallBackEvent.Event:Connect(resetCallback)
game:GetService("StarterGui"):SetCore("ResetButtonCallback", resetCallBackEvent)

Server Side:

local respawnPlayer = game:GetService("ReplicatedStorage"):WaitForChild("RespawnPlayer")

local function respawn(player)
    player:LoadCharacter()
end

respawnPlayer.OnServerEvent:Connect(respawn)

This ofcourse only applies to resetting but you could probably find a hacky way to get past that.

Ad

Answer this question