My button script is not working

So I have this script:

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local focusPart = game.Workspace.FocusPart

script.Parent.MouseButton1Click:Connect(function()
	if _G.ongoing == false then
		cam.CameraType = Enum.CameraType.Custom
		cam.CameraSubject = player.Character.Humanoid
	elseif _G.ongoing == true then
		print("Round ongoing")
		script.Parent.Parent.Parent.Status.Visible = true
		script.Parent.Parent.Parent.Status.Text = "There is currently a game ongoing! Please wait until a new round starts."
	end

end)

I am trying to make it so when a player clicks a button, if a round is not ongoing, their camera gets reset. Otherwise, make a status message pop up. I am not getting any errors in the output. Any help? The _G variable is declared inside a server script.

1 Like

Which part of it isn’t working? The spectating part or the message pop up?

The message pop up, and I am unsure why.

Print the ongoing variable and see if it’s true or false then firstly, or is the print printing?

It prints as nil, perhaps _G variables work differently on local scripts?

_G is not shared between client and server. Client’s _G is their own client and the server is server.

That’s your issue then, nil will become false in an if statement, hence why it doesn’t work. Instead of using .G, I would reocmmend making a BoolValue to contain if the game is ongoing or not and make it reference that instead. Make sure you make the BoolValue change from the Server and not client, otherwise you’d have another issue haha

1 Like

Alright, I’ll try it out. Thanks.

2 Likes