Script won't make a button Visible/Invisible on MouseButton1Click

Hello! So I recently have been trying to make a character selection system for a new game, and I am trying to make it so only one person can claim a character if an IntValue in workspace is set to 1. However, whenever I click the button while the IntValue is 1, it doesn’t do anything except disable a script that it is supposed to do. I have tried everything and I can’t get it to work.

Script: (In ServerScriptService)

game.StarterGui.LoadingScreen.Frame2.Bob.MouseButton1Click:Connect(function()
	if game.Workspace.Value1.Value == 1 then
		game.StarterGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = true
		game.StarterGui.LoadingScreen.Frame2.Bob.Visible = false
		game.StarterGui.LoadingScreen.Frame2.Bob2.Visible = true
		wait(4)
		game.StarterGui.LoadingScreen.Frame2.Bob.Visible = true
		game.StarterGui.LoadingScreen.Frame2.Bob2.Visible = false
	else
		game.StarterGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = false
		game.Workspace.Value1.Value = 1
	end
end)
2 Likes

StarterGui should only be managed with local scripts. Since it’s the UI, which is client-sided and shown locally to each client. If you need to manage a player’s UI from a server script then reference the player’s PlayerGui instance which is parented to them.

player:WaitForChild("PlayerGui").LoadingScreen.Frame2.Bob.MouseButton1Click:Connect(function()
	if game.Workspace.Value1.Value == 1 then
		player.PlayerGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = true
		player.PlayerGui.LoadingScreen.Frame2.Bob.Visible = false
		player.PlayerGui.LoadingScreen.Frame2.Bob2.Visible = true
		wait(4)
		player.PlayerGui.LoadingScreen.Frame2.Bob.Visible = true
		player.PlayerGui.LoadingScreen.Frame2.Bob2.Visible = false
	else
		player.PlayerGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = false
		game.Workspace.Value1.Value = 1
	end
end)
3 Likes

Sorry for the late response, I used that script but nothing happened.

2 Likes

Well yeah, you’d need to to define the player instance first, I’m not going to do everything for you. Since it’s a server script you won’t be able to use “game.Players.LocalPlayer”.

2 Likes

I did

local player = game.Players.LocalPlayer

player:WaitForChild("PlayerGui").LoadingScreen.Frame2.Bob.MouseButton1Click:Connect(function()
	if game.Workspace.Value1.Value == 1 then
		player.PlayerGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = true
		player.PlayerGui.LoadingScreen.Frame2.Bob.Visible = false
		player.PlayerGui.LoadingScreen.Frame2.Bob2.Visible = true
		wait(4)
		player.PlayerGui.LoadingScreen.Frame2.Bob.Visible = true
		player.PlayerGui.LoadingScreen.Frame2.Bob2.Visible = false
	else
		player.PlayerGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = false
		game.Workspace.Value1.Value = 1
	end
end)
2 Likes

Check the last part of my recent reply.

2 Likes

Alright, I changed it and nothing still happens.

Just had to put it in a LocalScript, everything works!

Testing it outside of Studios, it doesn’t work in the game

Found out whenever someone resets, then it says it’s claimed

Why yo waiting 4! Do some task waiting instead!

task.wait(4)

reason it didnt work in a server script was because script doesnt support LocalPlayer, only LocalScript does. so usually just do game.Players.PlayerAdded:Connect(function(player) --code-- end)