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

Need help with walkspeed change when gamepass is bought?

Asked by 8 years ago
Edited 8 years ago

Hello! I'm having an issue. I want a script to change the player's walkspeed when a gamepass is bought. I've tried a lot of scripts. So I've decide to ask people. Here's the script I'm working on that lets you buy it. I just need it to make you walk faster.

local player = game.Players.LocalPlayer


local id = 480546823


script.Parent.MouseButton1Down:connect(function()
game:GetService("MarketplaceService"):PromptPurchase(    player, id)
end)


1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Your first part for PromptPurchase is done! Good job!

Now, for the second part, making the effects.

We use the PromptPurchaseFinished event which can be accessed in MarketplaceService. Then, we connect it with a function which will give the game effects to the buyers (players who bought the pass).

Here are the edited scripts:

LocalScript in a button:

local player = game.Players.LocalPlayer
local id = 480546823
local mps = game:GetService("MarketplaceService") -- Not necessary, but it's a variable for MarketplaceService.

script.Parent.MouseButton1Down:connect(function()
    mps:PromptPurchase(player, id)
end)

Server Script in ServerScriptService:

local id = 480546823
local mps = game:GetService("MarketplaceService") -- Not necessary, but it's a variable for MarketplaceService.

mps.PromptPurchaseFinished:connect(function(player, assetId, isPurchased) -- The function contains 3 parameters: The player who bought the pass, the ID of the pass and a boolean to determine whether the player bought the pass.
    if isPurchased and assetId == id then -- If the player ACTUALLY paid for the pass.
        player.Character:WaitForChild("Humanoid").WalkSpeed = 20 -- Change to any speed you like.
    end
end) -- I forgot to add a ")", sorry about that.

If you have any problems please leave a comment below. Thank you and I hope this will help you.

0
It didn't work. But I think I know why, I put a LocalScript under a button GUI, so when you hit the button it gives you the message to buy it. Does that have something to do with it? yhatayhatahoohoo 15 — 8y
0
its better to leave the last part (9-13) being handled by a serverside script davness 376 — 8y
0
I updated the script, take a look again. starlebVerse 685 — 8y
0
doesnt work, i had a friend test it and it didnt work for him... yhatayhatahoohoo 15 — 8y
0
how can it not work, like any errors or problems? starlebVerse 685 — 8y
Ad

Answer this question