Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Clicked Event with GUI not getting past checking if player exists?

I'm trying to setup a click event that sets up the GUI with the information it needs. It never gets past the FindFirstChild event and I don't undertsand why.

Cart = script.Parent.Settings.CartName.Value

script.Parent.Button.Click.MouseClick:connect(function(p)
	local PlayerName = p
	if game.Players:FindFirstChild(PlayerName) then
		if game.Players.PlayerName.PlayerGui:FindFirstChild("Purchase") then
			print("Nope")
		else
			Pur = game.Lighting.Purchase:Clone()
			Pur.PurchaseScreen.PurchaseLabel.Text = "Purchase the "..Cart.."?"
			Pur.PurchaseScreen.MinSpeed.Text = "Max Speed: "..game.Workspace.Settings.Carts.MinSpeed[Cart].Value..""
			Pur.PurchaseScreen.MaxSpeed.Text = "Min Speed: "..game.Workspace.Settings.Carts.MaxSpeed[Cart].Value..""
			Pur.PurchaseScreen.Cost.Text = "Price: "..game.Workspace.Settings.Carts.Prices[Cart].Value.."c"
			Pur.CartName.Value = Cart
			Pur.Parent = game.Players.PlayerName.PlayerGui
		end
	end
end)

1 answer

Gui code should be handled with local scripts for maximum responsiveness, and this also makes it easy to get a reference to the local player.

-- In a LocalScript in the button
local button = script.Parent
local player = game.Players.LocalPlayer

button.MouseButton1Click:connect(function()
	if player.PlayerGui:FindFirstChild("Purchase") then
		print("Nope")
	else
		-- etc..
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.