Teleport only working once

I think I have a problem scripting between the client and the server.
I have a script in a part and when you touch the part, it enables a gui.
Inside this gui are pictures of places and when you click on one, there is a local script that teleports the player and disables the gui.

The problem is that it only works once and then it won’t work again.
I think I am turning it on with the server and then off on the client and so I think I need to make some kind of remote event, but I’m not sure how.

Here are my scripts (I also tried doing visible instead of enabled but still wouldn’t work.)

script

debounce = false

script.Parent.Touched:Connect(function(hit)
	local char = hit.Parent
	local hum = char:FindFirstChild("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(char)
	if hum ~= nil and player ~= nil and debounce == false then
		player.PlayerGui.Teleport.Enabled = true
		debounce = true
		wait(2)
		debounce = false
	end
	
end)

local script

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if player and player.leaderstats.Power.Value >= 1000 then
		player.Character.HumanoidRootPart.CFrame = game.Workspace.Jungle.Jungle1.JTeleport.CFrame
		player.PlayerGui.Teleport.Enabled = false
	else
		--warn not enough power to teleport
	end	
end)	
1 Like

You were right, you need to setup a remote event to do this. :FireClient() a remote event to toggle the teleport enabled value on the client.

1 Like

Thanks, I figured out a work around where I clone the gui from replicated storage and destroy it each time.
I came back here to share it, but do you see any downside to doing it this way versus the way I originally planned in your solution?

I don’t know actually. The only way I could think of is that your way save some memories(correct me if im wrong).

Yeah, cloning didn’t work either, so I created the remote event and it works great.
Idk why, but I feel so intimidated when trying to setup new remote events or functions.