Script not working(After death, all variables are inaccessible)

I’m sorry if im not too detailed on my response.

The main problem is, is that whenever to access a frame inside of a gui, it is nil despite, being visibly there.

DistanceTracker.Update = function(player,t_)
	local character = player.Character or player.CharacterAdded:Wait()
	local root = character:FindFirstChild("HumanoidRootPart")

	return RunService.Heartbeat:Connect(function()
		if not DistanceTracker.Ratios[player] then return end
		local playerFrame = UI:FindFirstChild("Scale"):FindFirstChild(player.Name)
		local ratio = (root.Position - workspace.RaceTracks.Starter.RaceSpawn.Position).Magnitude/t_[3] --// distanceTraveled / entireDistanceToGain
		playerFrame.Position = UDim2.fromScale(ratio,0.5)
		DistanceTracker.Ratios[player] = ratio
	end)
end

When I call this function, which is during a racing system/event in the game, I try to get the Scale frame to track every players distance from start to finish.

but if a player decided to reset, it would be inaccessible and many other errors are happening in other scripts when a player dies.

I’ve had this issue several times in the past and there aren’t any posts I can find talking about it.

Is this a ScreenGui? ScreenGui will often reset and be replaced automatically, clearing all references with variables, on the next character load. Have you tried disabling ScreenGui.ResetOnSpawn ?

Yeah its a screengui, I never though of disabling ScreenGui.ResetOnSpawn but nothing changed for me.

I tried moving the module above into replicatedstorage and only accessing it as PlayerGui but that wouldnt work.

1 Like

I found the issue btw, It is because the ResetOnSpawn behavior needed to be received from StarterGui or something like that and not put in a folder(I parented my gui to a folder).

Make sure you mark your reply as the solution :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.