Remote event giving me a mental breakdown

help. server:

local pizzeria = game.ServerStorage:WaitForChild("Pizzeria")
local assetnumber = tostring(#pizzeria:GetDescendants())
print(assetnumber)
pizzeria.Parent = workspace
game.ReplicatedStorage.LoadingRemote:FireAllClients(assetnumber)
print("Sent variable, terminating script")
task.wait()
script.Enabled = false

client:

local number = 0
game.ReplicatedStorage.LoadingRemote.OnClientEvent:Connect(function(assetnumber)
	print("Client fired")
	while number ~= assetnumber do
		print(assetnumber)
		print(number)
		workspace.Pizzeria.DescendantAdded:Connect(function()
			print("Connected")
			number += 1
			if number == assetnumber then
				script.Parent.Text = "Assets loaded: " .. number .. "/" .. assetnumber
				print("updated text")
			end
		end)
		task.wait(0.1)
		print("Loop ended")
	end
end)

what this does is add the number until it reaches the number of assets to check if the map loaded. please help this gave me a headache. the remote isn;t even firing. yes it is exactly in the specified place:
image

Is your remote event just not working or something?

not firing at all. yes indeed roblox shut

the server loads faster than client, results that the event is fired before function is even connected

1 Like

@bloodbonniekingnoob1 is this the full server script or just a part?

local pizzeria = game.ServerStorage:WaitForChild(“Pizzeria”)
local assetnumber = tostring(#pizzeria:GetDescendants())
print(assetnumber)
pizzeria.Parent = workspace
game.ReplicatedStorage.LoadingRemote:FireAllClients(assetnumber)
print(“Sent variable, terminating script”)
task.wait()
script.Enabled = false

If you’re trying to get when the game loads there is a command for it, it’s game:IsLoaded() for a script it would be something like:


if not game:IsLoaded() then
	game.Loaded:Wait()
end

2 Likes

it is since it prints faster huh… weird.

I don’t see the purpose of you turning this into a string, print(assetnumber) will automatically convert this into a string

plus, you are comparing a string to a number becuase of the tostring() conversion, which will always return false.

print("1" == 1)
--> false
print(1 == 1)
--> true
1 Like

local assetnumber = tonumber(#pizzeria:GetDescendants())

so, try to add task.wait(1 or so) before firing remote to clients

most likely the error lies in the fact that it uses “FireAllClients” too early, so @RonClon_TM says correctly

Wait I have an idea, add


if not game:IsLoaded() then
	game.Loaded:Wait()
end

At the start of the script, this way you will be able to get when everything is loaded

its not the thing, since it is server-side issue

Best use

game.Players.PlayerAdded:Connect(function(player)
  wait(player.CharacterAdded)
  if (#player:GetChildren > 1) then
  --nd
  else -- this only for first player add pizzeria
local pizzeria = game.ServerStorage:WaitForChild("Pizzeria")
local assetnumber = tonumber(#pizzeria:GetDescendants())
print(assetnumber)
pizzeria.Parent = workspace
game.ReplicatedStorage.LoadingRemote:FireAllClients(assetnumber)
print("Sent variable, terminating script")
task.wait()
script.Enabled = false

xd why you marked that as a solution?)

1 Like

maybe the error was not in the script, but in something else

1 Like

MISCLICK NO anyways fixed that.
and i proceeded to accidentally marked another answer as the solution end me

Yes I just got notified because you marked me as the solution :rofl::rofl::rofl: misclicks are the worst :rofl::rofl::rofl:

1 Like

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