GUI disappears after I respawn even while ResetOnSpawn is enabled

Hi, I have a GUI that indicates the player’s velocity. It works fine until you die and respawn. I’m not sure why it’s happening, it shouldn’t be.

As you can see:
image

ResetOnSpawn is true, so it should be there regardless of dying right?
Well, for some reason that’s not happening

There are no errors in the output, so I have no way to pinpoint what’s causing this.
This isn’t a studio-only bug either, it happens in the actual game too and I really do not know why

This is the only code in the GUI

A local script to update the text

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local text = script.Parent

function roundNumber(num, numDecimalPlaces)
	return string.format("%." .. (numDecimalPlaces or 0) .. "f", num)
end

game:GetService("RunService").RenderStepped:Connect(function()
	local velocity = (character.HumanoidRootPart.Velocity * Vector3.new(1,0,1)).Magnitude
	text.Text = roundNumber(velocity, 1)
end)

Any help is appreciated, thank you in advance

3 Likes

Yeah, u just said your problem, reset on Spawn is enabled, so disable it.

Reset on Spawn means, your GUI will be reseted to the First GUI Settings (All what is inside) so make it false and it will not change if you die.

2 Likes

not sure why that worked but epic
now there’s a new problem, the GUI stops updating after respawning

You don’t check if the player respawns, so it tries to get the velocity of a part that no longer exists

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local text = script.Parent

function roundNumber(num, numDecimalPlaces)
	return string.format("%." .. (numDecimalPlaces or 0) .. "f", num)
end

game:GetService("RunService").RenderStepped:Connect(function()
    local character = character or player.CharacterAdded:Wait()
    local root = character:WaitForChild("HumanoidRootPart", 3)

    if root then
	    local velocity = (root.Velocity * Vector3.new(1,0,1)).Magnitude
	    text.Text = roundNumber(velocity, 1)
    end
end)

not sure why this didn’t fix the issue. It should have
It just stays stuck on a random value after respawning. No errors or anything

I think i managed to fix the issue
Using a part of @uwuCulturist 's script:

put this with the UI

Vel = script.Parent.Vel -- Just ther name of the Variable i used

plr = game.Players.LocalPlayer

IsActive = true

plr.CharacterAdded:Connect(function()
	IsActive = true
end)

plr.Character:WaitForChild("Humanoid").Died:Connect(function()
	IsActive = false
wait()
Vel.Text = "0.0"
end)

function roundNumber(num, numDecimalPlaces)
return string.format("%." .. (numDecimalPlaces or 0) .. "f", num)
end

while IsActive == true do
	task.wait()
	local hrp = (plr.Character.PrimaryPart.Velocity * Vector3.new(1,0,1)).Magnitude
	Vel.Text = roundNumber(hrp, 1)
end


nope.
Still stays stuck after a respawn

Strange, i tested this out, works for me.

It shouldnt get stuck due to the Bool, The Bool is there to stop the Loop when the player is dead, and Activate when the Players Character added back. just so it can redetect the Players PrimaryPart

not sure if it matters, but the script is located in a textlabel so I had to edit your code to fit the textlabel parent thing (only had to edit line 1 and remove .vel from the end lo)

There is no error(s) in the output, I don’t know why this is happening

Ah, Ok i see my issue, Enable ResetOnSpawn, Should fix it

back to the same problem i had when i made the post initially, GUI disappears after I die

Look at your scripts, are you sure there isnt a line interfering with the UI?

everything else works fine, I have several GUIs like the GUI that unlocks your mouse or the server region indicator that all work just as intended. I’m not sure why this one doesn’t for some reason.

Edit: Read through other scripts, and I found out that there’s a chance that the main menu may have something to do with it but I can’t exactly pinpoint it

Edit 2: Nevermind that, I changed a couple of things and it made 0 difference, so it can’t be the Menu. The same bug still happens-- value gets frozen after respawn, does not work ever again during the play session

Strange,

I have never had any issue while testing, UI just doesnt disappear,

Are you sure that your “Intro” or any other script isn’t interfering with it?

No, i tried debugging with prints and it yields the same buggy result

Then make the Frame Visible again if you reset.

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local text = script.Parent

text.Visible = true --

function roundNumber(num, numDecimalPlaces)
	return string.format("%." .. (numDecimalPlaces or 0) .. "f", num)
end

game:GetService("RunService").RenderStepped:Connect(function()
	local velocity = (character.HumanoidRootPart.Velocity * Vector3.new(1,0,1)).Magnitude
	text.Text = roundNumber(velocity, 1)
end)

How are u making your Frame/Gui Visible? If you have it Enabled without a Script, it should be enabled again if you respawn with ResetOnSpawn Enabled.