Loading Screen Resets On Spawn

Hey, I am working on a loading screen, and it plays when I join, but every time I reset it plays again.


I have ResetOnSpawn checked off, and it still happens.

local buttonsGui = script.Parent.Parent.Parent.Buttons.ButtonsGui
local loadingGui = script.Parent
local loadingFrame = loadingGui:WaitForChild("MainFrame")

local ts = game:GetService("TweenService")

local backgroundFrame = loadingFrame:WaitForChild("BackgroundBar")
local movingBar = backgroundFrame:WaitForChild("MovingBar")

local buttonsFrame = buttonsGui:WaitForChild("ButtonsFrame")

local loadingTime = 3
local hasLoaded = false

local function tweenOut()
	local tween = ts:Create(loadingFrame, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = UDim2.new(0.5, 0, -1.5, 0)})
	tween:Play()
end

local function startLoading()
	print("Loading")
	buttonsGui.Enabled = false
	loadingFrame.Visible = true
	hasLoaded = true
	movingBar.Size = UDim2.new(0, 0, 1, 0)
	local tween = ts:Create(movingBar, TweenInfo.new(loadingTime, Enum.EasingStyle.Linear), {Size = UDim2.new(1, 0, 1, 0)})
	tween:Play()
	
	tween.Completed:Connect(function()
		buttonsGui.Enabled = true
		tweenOut()
		task.wait(0.7)
		loadingFrame.Visible = false
	end)
end

if not hasLoaded then
	startLoading()
end

Loading prints every time I respawn. Thank you, and let me know if you need anything else from me! (Script prob is not the best lol)

EDIT:

1 Like

Where exactly are these items parented to? I assume its replicated first, if possible send a screenshot of the relevant explorer portion

2 Likes


In starterGui inside a folder.

2 Likes

And is the script you sent earlier the full script? I feel like theres something else referencing LoadingGui

2 Likes

Yes, it is the only thing that has anything to do with the loading bar. I do have a script that sets the players base and stuff, but I do not think that would have to do with it. (I asked AI also, and it could not help me)

I am going to test it in a different place to see if something else might be messing with it.

1 Like

Ok I noticed something while it may not fix your issue would be useful to change,

tween.Completed:Connect(function()
...
end)

Having a :Connect() on a function you call more than once can worsen performance,
I would use:

tween.Completed:Once(function()
...
end)

if functioning remains the same

1 Like

How do you manage players when they respawn?

I think I just got it. Hang on I will test a little bit more!

1 Like

I just teleport them back to their base

yes but how exactly, do you use :MoveTo after their character is loaded, or maybe you load the character yourself?

1 Like
function BaseService.teleportToBase(plr, base)
	base = base or baseOfPlayer[plr]
	if not base then return end
	local spawnPad = base:FindFirstChild("SpawnPad")
	local chr = plr.Character
	if spawnPad and chr then
		chr:PivotTo(spawnPad.CFrame + Vector3.new(0, 5, 0))
	end
end

I do this to teleport them to the base. And call it here

	player.CharacterAdded:Connect(function(chr)
		task.wait()
		applyWalkSpeed(player, profile)
		BaseService.teleportToBase(player, base)
	end)

and here

	if player.Character then
		applyWalkSpeed(player, profile)
		BaseService.teleportToBase(player, base)
	end

I got it. So this is weird, but the AI helped me and said this:


So I just moved it out of the folder, and now it works… hmm ok.

Thank you for your time and assistance! Have a good day!

2 Likes

yea i was just about to say that too, personally I’ve had bugs when i tried to organize UIs in folders but now we know for sure.

1 Like

Your loading GUI should absolutely be in ReplicatedFirst, not StarterGUI. At the beginning of the video you can see the other GUI loaded first, which can be avoided by allowing ReplicatedFirst make your GUI before anything else is.

1 Like

Okay, I will do this. Thank you!