GUI opening script only works once

I have a part in my game that, when clicked, makes a GUI frame visible and anchors the player’s HumanoidRootPart, LowerTorso, and Uppertorso. Then, when you click a TextButton in the GUI’s frame, it hides the GUI frame and unanchors the anchored parts. These scripts work fine on the first click, but when I try them again, the GUI does not get opened, and the player does not get anchored.

Script: (ServerScript)

function onClick(click)
	local ItemGui = click.PlayerGui.Gui
	if ItemGui.Frame.Visible == false then
	ItemGui.Frame.Visible = true
	print("view")
		click.Character.HumanoidRootPart.Anchored = true
		click.Character.LowerTorso.Anchored = true
		click.Character.UpperTorso.Anchored = true
		end
	end

	script.Parent.ClickDetector.MouseClick:connect(onClick)

TextButton Script: (LocalScript)

script.Parent.MouseButton1Click:Connect(function(click)

game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = false

game.Players.LocalPlayer.Character.LowerTorso.Anchored = false

game.Players.LocalPlayer.Character.UpperTorso.Anchored = false

game.Players.LocalPlayer.PlayerGui.Gui.Frame.Visible = false

end)

Video Demonstration

How do I fix this?

The server can’t see that the ui isn’t visible because you made the ui invisible using a localscript.

The server cannot see what you did on the client.

1 Like