Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[UNANSWERED]Why isn't this scripting working correctly!?

Asked by
Andorks 23
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)

2 answers

Log in to vote
0
Answered by 9 years ago

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.

Ad
Log in to vote
2
Answered by 9 years ago

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)
0
Thanks! Andorks 23 — 9y
0
Now it doesn't work.. Andorks 23 — 9y
0
'PromptPurchase' does not work within a LocalScript; It is Server-Sided only sadly. TheeDeathCaster 2368 — 9y
0
So, I should put it in a script? Andorks 23 — 9y
View all comments (5 more)
0
You could, but, that will take a lot more editing of the code. :/ TheeDeathCaster 2368 — 9y
0
So, I have to edit it, or it won't work :/ Andorks 23 — 9y
0
Yep, pretty much. :/ You would have to edit the code so that it knows which target (the Player) is (As those repeatedly use the script.Parent.Parent until it reaches the Player). TheeDeathCaster 2368 — 9y
0
Sad thing is, it's in a surfacegui Andorks 23 — 9y
0
Helping him in ROBLOX PM's. alphawolvess 1784 — 9y

Answer this question