Scripts breaking in Roblox but working in Studio

I’m finalizing a foundation of my game but when I test my game with an alt on roblox, the game breaks in numerous ways.

The round system never shows the voting, the rounds are broken, winning does not work, and etc.

I have to make a 10 seconds delay for the round system to send a vote to everyone.

My main menu (in the replicated first) is sent a signal to edit the client’s camera. The problem is, I don’t think it is optimized enough to do that on Roblox (or it might be because I was in a server with 2 people).

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")

local Gui = script.MainGui:Clone()

local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui

local PlayButton = Gui.Frame.PlayButton
local Start = script.Start.Value

local Camera = workspace.CurrentCamera

Gui.Parent = PlayerGui

PlayButton.MouseButton1Up:Connect(function()
	Gui:Destroy()
	Camera.CameraType = Enum.CameraType.Custom
	Remotes.ToServer:FireServer("PlayerJoined")
end)
-- fires when the players character is added only once using(player.CharacterAdded:Wait())
Remotes.ToClient.OnClientEvent:Connect(function(signal)
	if signal == "StartCamera" then
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = Start
	end
end)

I think this is majorly because of performance on Roblox and optimization.

Ever come across something like this?

When I join in the game and shift the wait down to 1. The voting gui never shows. Is this because of latency or something else?

I don’t think you provide enough information for me to help. Do you know what exactly is breaking? (is there any errors? have you used prints to check if some value is wrong or if the code is stopping at somewhere?)

From just looking at it, I don’t see anything wrong with the main menu script. I don’t believe theres any optimization issues unless whatever fires the ToClient event is ineffecient. (Although I am somewhat confused, why do you set the player camera’s CFrame to a specific value when the player character is added? That seems like a very strange thing to do.)

The server script handling the round is breaking. Specificially the voting system needs a 10 second delay in order to work. I think this is due to latency but I’m not sure.

The main menu script is not my problem anymore (even though the camera isn’t really working also supposedly due to latency).

(sorry for the late reply, if you want me to see your reply, press the “reply” button below my post so I get notified!)

It would probably be helpful if you could provide us the script for the voting system (and possibly whatever activates it) so we (as in, anyone who might reply to this post) can see what might be the problem

Your script is checking if the game has loaded using an if statement; however, it only performs this check once.

The script will find that the game has not yet loaded, and therefore, it will yield for a brief amount of time using :Wait() and will then resume execution of the program. By continuing execution of the script before the game has loaded, everything breaks (like as you say).

To solve this problem, you need to be constantly checking if the game has loaded, and once it has, continue execution. This can be done using a repeat-until loop:

repeat task.wait() until game:IsLoaded()

-- From here, the program will continue to execute as the game has now fully loaded
1 Like

Sorry, I’ve solved this issue, I used a loading screen and many other methods that would make the game function.

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