Need help with ReplicatedFirst

This is a really simple thing that I have managed to do before but aren’t able to do so now that I’m back after years, essentially I’m starting all over again (not that I was even experienced before) and want to begin with simple things such as Guis and simple code.

What I have here is a loading screen that doesn’t appear when I place it in ReplicatedFirst.

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local TweenService = game:GetService("TweenService")

local plr = Players.LocalPlayer
local gui = script.LobbyLoadingUI
local plrGui = plr:WaitForChild("PlayerGui")
local Main = script.LobbyLoadingUI.Main

local Bar = Main.Holder.Bar 
local Assets = Main.Holder.AssetsLoaded -- text label that shows amount of assets loaded (all game descendants)
local skip = Main.Skip -- skip button that appears after 6 seconds if not finished loading

local tweenskip = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false)
local tweenrotate = TweenInfo.new(1.2,Enum.EasingStyle.Circular,Enum.EasingDirection.In,-1,false)
local UIGrad = skip.UIStroke.UIGradient

local TweenSkipBtn = TweenService:Create(skip, tweenskip, {skip.Position.Udim2.new(0,0,0.5,0)})
local TweenRotateGrad = TweenService:Create(UIGrad, {Rotation = 360})

gui.Parent = plr -- Not sure if this helps 

ReplicatedFirst:RemoveDefaultLoadingScreen()

if not game:IsLoaded() then -- is this necessary?
--skip button
wait(6)

	if Main.Enabled == true then
		skip.Visble = true
		TweenSkipBtn:Play()
		
		task.wait(3)
		
		UIGrad.Enabled = true
		end
		
		if UIGrad.Enabled == true then
			TweenRotateGrad:Play()
		end
	end

I’m not sure what else am I missing that the ui does not appear. This is a localscript under ReplicatedFirst, and under this script is a ScreenGui I name ‘LobbyLoadingUI’ (Enabled turned on, works fine if its placed under StarterGui)

Also, just wanted to know in addition if I’m writing the tweeninfos correctly? I’ve always tweened UIs using ’ :Tweenposition(UDim2.new()) ’ so this is quite new to me.

1 Like

You should be parenting it to PlayerGui, not the player

You did some things incorrectly here. Firstly the third argument of Create is a dictionary with properties to be tweened, for example {Position = UDim2.new(), Rotation = 52}. This should be what it looks like for the first tween:

local TweenSkipBtn = TweenService:Create(skip, tweenskip, {Position = UDim2.new(0,0,0.5,0)})

You also forgot to add in the TweenInfo for the second tween.

It isn’t necessary but having it is also a good idea. There is a chance of the game already being loaded, making the code not running. You should consider putting it outside the if statement instead:

ReplicatedFirst:RemoveDefaultLoadingScreen()

local loaded = game:IsLoaded()
local timeLoaded = 0 -- time loaded

if not loaded then
	task.spawn(function() -- prevent code from yielding
		game.Loaded:Wait() -- wait until loaded
		loaded = true
	end
end

repeat timeLoaded += task.wait() 
until loaded or timeLoaded >= 6 -- yield code until game is loaded or 6 seconds have passed

if Main.Enabled == true then
	skip.Visble = true
	TweenSkipBtn:Play()

	task.wait(3)

	UIGrad.Enabled = true
end

if UIGrad.Enabled == true then
	TweenRotateGrad:Play()
end
1 Like

Thanks so much! I always tend to overlook in whatever I do,

However when I parented the gui to PlayerGui instead, still nothing happens
There seems to be this warning though, not sure if its correlated:

StarterGui:SetCoreGuiEnabled must be called from a local script.

It’s probably from another script, I don’t see anything related to StarterGui.

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