Not detecting ui is invisible

I’m trying to make this script check if a Frame is visible before letting it do anything.

Its printing that the ui is visible both when it is and when its not.

I searched it up and it looks like nobody has the problem.

Here is the code

script.Parent.Touched:Connect(function(hit)
	print("go")
	local random = math.random(1, 3)
	local char = hit.Parent
	local humanoid = char:FindFirstChild("Humanoid")
	if humanoid then
		print("humanoid")
		local plr = game.Players:FindFirstChild(char.Name)

		if plr.PlayerGui.tut.Frame.Visible == false then
			
			print("is not visible")
			if random == 1 then
				char:MoveTo(game.Workspace.spawn1.Position)
			elseif random == 2 then
				char:MoveTo(game.Workspace.spawn2.Position)
			elseif random == 3 then
				char:MoveTo(game.Workspace.spawn3.Position)
			end


			char.force.Visible = true





			local b = game.ReplicatedStorage.HK416:Clone()
			b.Parent = plr.Backpack


			local c = game.ReplicatedStorage.MP5:Clone()
			c.Parent = plr.Backpack



			local d = game.ReplicatedStorage.R700:Clone()
			d.Parent = plr.Backpack


			local e = game.ReplicatedStorage.USP:Clone()
			e.Parent = plr.Backpack

			wait(5)

			char.force:Destroy()
			
		else 
			print("is visible")
		end
	end


end)

Thank you for helping

Well, if this script you wrote here is a server script and the script that makes the UI invisible/visible is a local script, then that is your problem. Changes made on the client can only be recognized on the client. You would have to use an event such as a RemoteEvent to send that information between client to server

Hope this helps!

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