I keep getting the error code: Unable to cast the value to Object I do not see anything wrong, please help. My code I am using is:
--andorks script.Parent.MouseButton1Down:connect(function(player) game:GetService("MarketplaceService"):PromptPurchase(player, 16630147) end)
This is a bit tricky, considering the parent of the script, but the steps are fairly basic.
Step 1:
Move the entire SurfaceGui (not the brick, though) into StarterGui. Then, select the SurfaceGui, hold Ctrl, and select the brick it was in before. Without deselecting either item, type this in the command bar: local s=game.Selection:Get() s[1].Adornee=s[2]
This should allow the SurfaceGui to function from StarterGui.
Now for the main code. Type this in a regular script inside of the button.
local player=script.Parent.Parent.Parent.Parent --Order of parents: button, SurfaceGui, PlayerGui, player local id=0 --insert ID of asset here function click() --initiate our function game:GetService("MarketplaceService"):PromptPurchase(player,id) --don8 pl0x end --end our function script.Parent.MouseButton1Click:connect(click) --connect the function to the MouseButton1Click event
That should do it! Contact me with any questions.
It's because of your "player" argument. MouseButton1Down doesn't return the Player who clicks, it return x/y coordinates. Instead, remove the argument in line 2: player
.
Now, change the player
argument in line 3 into this: game.Players.LocalPlayer
MAKE SURE IT'S A LOCAL SCRIPT, IF IT'S NOT, MAKE IT ONE
Your finished script will look like this:
--andorks script.Parent.MouseButton1Down:connect(function() game:GetService("MarketplaceService"):PromptPurchase(game.Players.LocalPlayer, 16630147) end)