GUI is still visible after changing it to false

I am trying to make a system for the cash register where the player is able to unclaim it. When I added the unclaim button, I want a text label visibility on a surface gui to be false and the visibility of a button to be true. However, when I did it on a server script, the visibility of the text label is still true and the text button visibility is true which isn’t what I want. May I know what is wrong and how to fix it? My script works on the person who pressed the button to unclaim a cash register but not for everyone else. I tried using remote events but it doesn’t seem to work.

Script on a button (Local script)

local button = script.Parent
local player = game.Players.LocalPlayer
local tweenservice = game:GetService("TweenService")
local screens = game.Workspace:WaitForChild("Screens")

button.MouseButton1Click:Connect(function()
	local stuff = screens:GetDescendants()
	for i,v in pairs(stuff) do
		if v:IsA("StringValue") and v.Value == player.Name then
			v.Parent.Visible = false
			v.Parent.Parent.TextButton.Visible = true
			if v.Parent.Parent.Parent.Parent.Name == "Screen1" then
				game.ReplicatedStorage.Changevalue1:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen2" then
				game.ReplicatedStorage.Changevalue2:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen3" then
				game.ReplicatedStorage.Changevalue3:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen4" then
				game.ReplicatedStorage.Changevalue4:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen5" then
				game.ReplicatedStorage.Changevalue5:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen6" then
				game.ReplicatedStorage.Changevalue6:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen7" then
				game.ReplicatedStorage.Changevalue7:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen8" then
				game.ReplicatedStorage.Changevalue8:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen9" then
				game.ReplicatedStorage.Changevalue9:FireServer(v)
			elseif v.Parent.Parent.Parent.Parent.Name == "Screen10" then
				game.ReplicatedStorage.Changevalue2:FireServer(v)
			end
			local tweeninfo = TweenInfo.new(1,Enum.EasingStyle.Bounce)
			local goals = {Position = UDim2.new(0.42, 0,1, 0)}
			local tween = tweenservice:Create(button,tweeninfo,goals)
			tween:Play()
		end
	end
end)

Server script

game.ReplicatedStorage.Changevalue1.OnServerEvent:Connect(function(player,v)
	print(v.Name)
	v.Parent.Visible = false
	v.Parent.Parent.TextButton.Visible = true
	v.Value = ""
end)

I highly, HIGHLY suggest using RemoteEvents or RemoteFunctions to interact with anything to do with UI or something that can only be seen by the client themselves.

For example. You could create a RemoteEvent in ReplicatedStorage that fires the client and tells the GUI to turn its visible value to false or true.

1 Like

I used remoteevents to the server

And you can also use RemoteEvents to the client. Here’s an example.

Server

wait(5)
game.ReplicatedStorage.OpenUI:FireAllClients(true)
wait(5)
game.ReplicatedStorage.OpenUI:FireAllClients(false)

Client

game.ReplicatedStorage.OpenUI.OnClientEvent:Connect(function(UI)
    script.Parent.Frame.Visible = UI
end)

So I just need to fire to the clients from the server?

Yes. It’s always good, for UI at least, to have a RemoteEvent be in the GUI so you can just fire it and control stuff on the client instead.

2 Likes

It works now! Thank you for helping me!

1 Like

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