GUI only works once on click

Hi! I’m trying to have a gui pop out when a part is clicked. The problem I’m running into is after I close it, it will never come out ever again. I’m not sure why. Here’s my code.

local colorClone

script.parent.ClickDetector.MouseClick:connect(function(player)
	if not player.PlayerGui:FindFirstChild("ColorPicker") then
		colorClone=script.parent.ColorPicker:Clone()
        	colorClone.Parent = player.PlayerGui
        	colorClone.Frame:TweenPosition(UDim2.new(0.537, 0, 0.52, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.33, false)
			colorClone.BackGround:TweenPosition(UDim2.new(0.338, 0, 0.25, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.33, false)
    		end
		end
end)

That’s in a script. I know having it in a localscript is way easier but as I’m going to share it, I don’t want another thing they would have to move into a different place.

Here’s the close script. This one is in a localscript.

script.Parent.Activated:Connect(function()
    pcall(function()
        game:GetService("Players").LocalPlayer.PlayerGui.ColorPicker.Frame:TweenPosition(UDim2.new(0.537, 0, -1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.33, false)
		game:GetService("Players").LocalPlayer.PlayerGui.ColorPicker.BackGround:TweenPosition(UDim2.new(0.338, 0, -1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.33, false)
        wait(0.33)
        game:GetService("Players").LocalPlayer.PlayerGui.ColorPicker:Destroy()
    end)
end)

Any help would be appreciated! Thanks in advance!

The problem is that you are destroying the ColorPicker from a LocalScript, and it will therefore not be :Destroy()ed on the server. This means that when you run the if statement that is looking for ColorPicker in the ServerScript, it will not continue since it still exists on the server. You create it on the Server, but :Destroy() it on the Client.

I would recommend just shifting all of your code to work on the client end. Then you would not have to worry about anything not replicating.

1 Like

Thanks! I thought it was that! For anyone stumbling across this post, I used a remoteevent from the client to receive the click and got used player for localplayer.

2 Likes