GUI Click Not Working

Hello. I’m trying to let the user be able to try on clothes on the serverside by pressing buttons of the GUI. When I press on the GUI nothing prints except for “duplicated”.
Here is the server script that fires the event:

local ProximityPromptService = game:GetService("ProximityPromptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage.Click

local shirtid = script.Parent.Config.shirtid
local shirtassetid = script.Parent.Config.shirtassetid
local pantsid = script.Parent.Config.pantsid
local pantsassetid = script.Parent.Config.pantsassetid
game.Players.PlayerAdded:Connect(function(Player)
	script.Parent.ProximityPrompt.PromptButtonHoldEnded:Connect(function()
		local count = 0
		for i,v in pairs(Player.PlayerGui:GetChildren()) do
			if v.Name == "TryOn" then
				count = count + 1
			end	
			if count > 2 then
				Player.PlayerGui.TryOn:Destroy()
			end
		end
		print(count)
		
		remoteEvent:FireClient(Player, shirtid.Value, shirtassetid.Value, pantsid.Value, pantsassetid.Value)
		print("fired")
	end)
end)

And here is the GUI local script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Click")
local Player = game.Players.LocalPlayer

local function onNotifyPlayer(shirtid, shirtassetid, pantsid, pantsassetid)
	local gui = Player.PlayerGui.GUI:Clone()
	gui.Name = "TryOn"
	gui.Parent = Player.PlayerGui
	gui.Frame.Visible = true
	print("Duplicated")
	--purchase pants
	script.Parent.PurchasePants.MouseButton1Click:Connect(function()
		game:GetService("MarketplaceService"):PromptPurchase(Player, pantsid)
		print("purchase pants clicked")
	end)
	-- purchase shirt
	script.Parent.PurchaseShirt.MouseButton1Click:Connect(function()
		game:GetService("MarketplaceService"):PromptPurchase(Player, shirtid)
		print("purchase shirt clicked")
	end)
	-- try on shirt
	script.Parent.TryOnShirt.MouseButton1Click:Connect(function()
		game.ReplicatedStorage.TryOnShirt:FireServer(shirtassetid)
		print("try shirt clicked")
	end)
	-- try on pants
	script.Parent.TryOnPants.MouseButton1Click:Connect(function()
		game.ReplicatedStorage.TryOnPants:FireServer(pantsassetid)
		print("try pants clicked")
	end)
end
remoteEvent.OnClientEvent:Connect(onNotifyPlayer)

The close button is a local script inside the button and it works just fine, so I’m not sure why it doesn’t work inside this local script.
Here is the GUI:
image

And inside game settings and security I turned on HTTP requests as well.
All help is appreciated!

1 Like

Maybe you didn’t fire the remoteEvent???

1 Like

When you click the button in the local script player will be nil because clicking a button only passes x and y values.

In the local script remove player from the Mouse Click function.
For clicking things, in local scripts you can make a variable
local Player = game.Players.LocalPlayer
and use that for anything, because it is a local script.

Examples

For PromptPurchase:

game:GetService("MarketplaceService"):PromptPurchace(Player, ID) 
--[[
Player is there sinced you specified Player as game.Players.LocalPLayer
]]

For FireServer:

game.ReplicatedStorage.YOURFUNCTIONNAME:FireServer(Player)

I know the event is fired because duplicated is printed but nothing else after that is

Is it possible if we could get a look at where you place your guis?

I updated the script, to use the player variable from game.Players.LocalPlayer, however it still doesn’t work.

1 Like

Sorry I’m lost, what does this mean?

Are you not getting the variable from the clientEvent or is it not prompting you with a purchase

Don’t put the player variable in the click function. Just use it for :PromptPurchase() and stuff like that.

I have another local script inside the close button and it’s working (aka it’s closing the gui)

Is there a reason you are cloning the UI, and can we look at the layout of the gui? Im just not seeing an issue.

Try changing MouseButton1Click to MouseButton1Down rarely, Click doesn’t work

I clone the UI since there’s multiple models with different asset ids so if I fire it to the same GUI it might use the first set of ids fired instead of the most recent one.

Also I can verify that the buttons work since I created a local script inside the purchase pants button that says this:

script.Parent.MouseButton1Click:Connect(function()

print("purchase pants is clicked!!! through local script")

end)

And it’s being printed

I think I see the problem. If you clone it , then it won’t work because the script is only focusing on the current one.

I’ll try finding the clone’s buttons and doing mousebutton click from there.

So then use Player.PlayerGui.TryOn.BUTTONNAME.MouseButton1Click:Connect(function()

Read post 18 first ---------------------------

Hehe yes it’s fixed, thank you so much for your help everyone!

1 Like