Super werid bug, I think I know why it happens but don't know how to stop it

I shrink it and did not work, I guess it has to be more shirnked.

Here’s your issue, you tween the client’s GUI on the server, which is bound to cause some desynchronization, basically;

  1. The server tweens the gui to the correct place on the client.
  2. The player presses yes/no and the client tweens the gui back to the top of the screen. Because of how replication works, this change wont be replicated to the server.
  3. Once the player goes to touch the teleporter again, the server sees that the GUI is still in the same place, so therefore it has no reason to do the tween if no changes would be made.

Ideally, most tweens and GUI transitions would be handled on the client, but for the sake of practicality; fixing this on the server should be simple:

local part = script.Parent
local deb = false

part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not plr or deb then
		return
	end

	local Screen = plr.PlayerGui["SecretStage1GUI"] -- ScreenGui name
	if plr.leaderstats.Coins.Value < 150 then
		Screen.NotHaveCoins.Position = UDim2.new(0.253, 0, -1, 0)
		Screen.NotHaveCoins:TweenPosition(UDim2.new(0.253, 0, 0.294, 0), "In", "Back", 1, true)
		deb = true
		wait(1)
		deb = false
	elseif plr.leaderstats.Coins.Value >= 150 then
		Screen.HaveCoins.Position = UDim2.new(0.253, 0, -1, 0)
		Screen.HaveCoins:TweenPosition(UDim2.new(0.253, 0, 0.294, 0), "In", "Back", 1, true)
		deb = true
		wait(1)
		deb = false
	end
end)

Paste that code into the script handling the .Touched event and everything should work. This basically just tells the server that whenever the teleporter is touched, it should reset the position of the GUI and tween it again. One notable behavior of this code though is that if the teleporter is touched while the GUI is on screen, the GUI would teleport off the screen and tween in again.

Yes is just clieny.

No is not which is why it works

I will try this though although I still think we have to make the yes script a regular script but I think romte events only work in local scripts.

This is my point, the client/server gets desynchronized when the client tweens an object without informing the server.

If, for some reason, the No button were registered on the server; the server would be updated on its changes.

If the Yes button were registered on the client; its changes wouldn’t be replicated to the server.

Also handling GUI events on the server is a VERY bad practice which could introduce a number of vulnerabilities and bad UX, I recommend handling GUI events on the client and using RemoteEvents to replicate button presses.

1 Like

Ok so script does work but two things

  1. Thank You!
  2. It seems to have it where if your on it the gui just goes up and dwn up and down.

I edited it but adding a wait(2) delay but there need to be a better way to do it.

local part = script.Parent
local deb = false

part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not plr or deb then
		return
	end

	local Screen = plr.PlayerGui["SecretStage1GUI"] -- ScreenGui name
	if plr.leaderstats.Coins.Value < 150 then
		Screen.NotHaveCoins.Position = UDim2.new(0.253, 0, -1, 0)
		deb = true
		Screen.NotHaveCoins:TweenPosition(UDim2.new(0.253, 0, 0.294, 0), "In", "Back", 1, true)
		wait(2)
		deb = false
	elseif plr.leaderstats.Coins.Value >= 150 then
		Screen.HaveCoins.Position = UDim2.new(0.253, 0, -1, 0)
		deb = true
		Screen.HaveCoins:TweenPosition(UDim2.new(0.253, 0, 0.294, 0), "In", "Back", 1, true)
		wait(2)
		deb = false
	end
end)

Yes but could I make the yes button a script and not a client and still have the remote event working?

This is because of the behavior I described earlier. When tweening GUIs on the server, there’s no elegant way to prevent this sort of behavior. The server has no idea what changes the client makes to the GUIs, so it just does its best to accommodate edge cases. If you want to avoid this behavior, I highly recommend that you add another .Touched event in a local script that handles the GUI tweening.

The server cannot fire RemoteEvents to itself.

Here are some possible solutions for you:

  1. Change the No button to be client-sided.
  2. Tween the GUI on the client and revert the .Touched event back to how it was previously.
  3. Leave it how it is now and/or raise the debounce to make the disappearing effect less noticeable.

This seems to be a common problem, I even fell victim to it. If you’re doing something involving GUIs, always try to do it client sided unless absolutely necessary

Times when it would be necessary to it from server is if it’s for admins only or something.

Also due to Client-Server boundary type stuff, if you make any changes to the client using a remote event to change it true, and the player hits an X button or something on the client, the server will still preceive that the GUI is open, and therefore won’t make any changes. Try to switch this system completely over to the client by dropping the script inside of StarterCharacterScripts, StarterPlayerScripts or ScreenGUI. I personally do StarterPlayerScripts because if it’s a script that doesn’t need to be reset it won’t reset on death or anything.

btw, the script must be a LocalScript, and must use :WaitForChild() to give the part with the touched event time to load.

Hope this helps.

1 Like