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:
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)
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)
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
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
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
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.