GUI only appearing one time when called

I made a Gui that activates when a part is touched. However, when I close said Gui (using a “No” button), the Gui does not reappear when part is touched again. Here is the script (ServerScript) I’m using:

local d = false

script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	d = true
    if player and d == true then
	    local pName = player.Name
	    local pGui = player.PlayerGui 
	
	    pGui.GameGui.Frame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), "Out", "Quint", 1, true)
    end
    d = false
end)

I can show the “No” button script as well if you need me to. Thanks in advance!

1 Like

When you pressed the “No” button, the changes it made to the GUI only shows to the client, not the server. To fix this, I’d suggest making this script client-sided.

Did you even use pName afterall?

No. I forgot to delete it from bug testing.

You didn’t seem to have added an wait(SecondsYouWant) in your debounce/script, it may be that.

This ^ should most definitely be on the client. Moving it to the client would also allow for smoother effects when tweening. With all that being said, I would also recommend using TweenService to move the Gui.

As far as your current script goes, here’s how I would’ve done it (if it were on the server)

local debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        local character = hit.Parent
        local player = game:GetService("Players"):GetPlayerFromCharacter(character)
        if player and debounce == false then
            debounce = true
            local playerGui = player.PlayerGui
            playerGui.GameGui.Frame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 1, true)
            debounce = false
        end
    end
end)

Technically, he is using TweenService, but using the :TweenPosition().

When I move my script into a LocalScript (changing the “local player” line to game.Players.LocalPlayer) the script does not respond at all. Should I move this LocalScript into ServerScriptService or do something else?

If you make it a LocalScript, I believe you can’t put it directly inside the part, instead, follow these steps:

  • Rename the part to something unique
  • Define a variable for the part in the LocalScript
  • Put the LocalScript in StarterPlayer -> StarterPlayerScripts

Then try

1 Like

I tested DataErased code, and it worked perfectly fine, i assume you, @iy_uhn, will mark his post as solved, if it didn’t solve for you, then i guess i can’t do anything anymore.

Don’t worry, I’m trying it right now; my Studio just crashed the first time I put it in :frowning:

1 Like