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

Need help with walkspeed change when gamepass is bought?

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

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.

5 comments

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?

0

its better to leave the last part (9-13) being handled by a serverside script

0

I updated the script, take a look again.

0

doesnt work, i had a friend test it and it didnt work for him...

0

how can it not work, like any errors or problems?

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