Why this only GUI work once

i made a shop pad(like the simulator), when i step on the pad , the shop show up but when i clicked close
, the shop closed . but when i stepped on the pad again , nothing happen.

here is the pad handler(located in ServerScriptService)(ServerScript)

local pad = workspace.ShopPad


pad.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local ShopMenu = player.PlayerGui:WaitForChild("MiddleGui").ShopMenu
		if player then			
			ShopMenu:TweenPosition(
				UDim2.new(0.301, 0,0.349, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Linear,
				.2,
				true
			)	
				
		end
	end
end)

here is the close button(located in StarterGui)(LocalScript)

local button = script.Parent.Button
local buttonFrame = script.Parent
local ShopFrame = script.Parent.Parent
--button animation
buttonFrame.MouseEnter:Connect(function()
	buttonFrame.ImageColor3 = Color3.fromRGB(159, 0, 2)	
end)

buttonFrame.MouseLeave:Connect(function()
	buttonFrame.ImageColor3 = Color3.fromRGB(255, 0, 4)	
end)
--button function
button.MouseButton1Click:Connect(function()
	ShopFrame.PopSound:Play()
	ShopFrame:TweenPosition(
		UDim2.new(-1, 0,0.349, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Back,
		1,
		true
	)
end)

Seems fine. Do you get any output errors? If not, try adding a print statement right before the tween in, to see if the code ever gets that far. If not, move it “outwards” one if- statement at a time to find out where exactly it goes wrong.

it only print once
.
.
.
.
.
.

If I’m right, you are opening the gui serverside and closing it client-side.

Because you close it client-side, the server will still think the GUI is opened and already tweened.

You have to tween the gui ONLY client-side or ONLY serverside. I recommend client-side since gui’s are on the client.

You could solve this problem by firing the client when the pad is touched with a RemoteEvent, so the client will tween the GUI to show up.

1 Like

i dont know why its not working when im using local script

here is the script(located in the pad, workspace)

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then
			local ShopMenu = Player.PlayerGui:WaitForChild("MiddleGui").ShopMenu
			ShopMenu:TweenPosition(
				UDim2.new(0.301, 0,0.349, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Linear,
				.2,
				true
			)
		end	
	end
end)

When the pad is touched, you should fire the client with RemoteEvent:FireClient(player)
and do the tweening on the client

the touch not even working

local tweenUI = game.ReplicatedStorage:WaitForChild("ShopRemote").tweenUI

script.Parent.Touched:Connect(function(hit)
	print("touched")-- i test if the Touched is work
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then
			tweenUI:FireServer(Player)
		end	
	end
end)

since this is already serverside, you have to fire the client, not the server, so you have to do

tweenUI:FireClient(player)

not

tweenUI:FireServer(player)

so the Server script should be OnClientEvent ?

OnClientEvent should be inside the localscript where you handle the tweening

serverside:

tweenUI:FireClient(Player)

clientside:

tweenUI.OnClientEvent:Connect(function()
       --do the tweening here
end)
2 Likes

oh i finally understand thank you so much