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

GUI Button doesn't define the user?

Hello everyone,

So I have this script for a GUI with a button. When clicked it does the following:

local ID = 4715972 --ID

script.Parent.MouseButton1Click:Connect(function(p)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(p.userId, ID) then
	print("I'm working :D")
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(p,ID)	
	end
end)

But then it gives this error: attempt to index local 'p' (a nil value).

It works with a normal button with a clickdetector but not for a GUI with a button. Why so and how do I fix this?

Game-pass (if neccessary idk): https://www.roblox.com/game-pass/4715972/

Thanks in advance! ~snewo12

2 comments

0

If this is a local script, use "local p = game.Players.LocalPlayer"

0

I get the following error: "players is not a valid member of DataModel"

1 answer

✓ Accepted answer

Okay, your problem is that MouseButton1Click for a GUI button doesn't return which player clicked it.

If it's a local script, just do local p=game.players.LocalPlayer

If its a server script in a player's GUI (Not sure why that would be the case, but whatever) You could do something like script.parent.parent.parent (until you got to the player)

If it's a server gui (like on a big block or something) just use a clickdetector behind a text box.

6 comments

0

I get the following errors in both a local and a server script: "players is not a valid member of DataModel"

0

Typo, try game.Players (Capital P)

0

My god, I feel stupid xD

0

Thank you, it worked!

0

Hey, can you please accept my answer? thanks. Also, you're welcome.

0

Done, thanks again!

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