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

Character Added and prompt game pass purchase doesnt work?

I wanted to make a shop, that if I click on buy, it will sent the player into the buying screen and when its bought, he is walking faster, but when he respawns, he loses his faster walk. Please help me!

local Marketplace = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	Marketplace:PromptGamePassPurchase(Player, 9586786)
end)


Marketplace.PromptGamePassPurchaseFinished:Connect(function(purchased)
	if purchased then
		Player.Character.Humanoid.WalkSpeed = 40
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if Marketplace:UserOwnsGamePassAsync(Player.UserID, 9586786) then
		Player.Character.Humanoid.WalkSpeed = 40
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if Marketplace:UserOwnsGamePassAsync(Player.UserID, 9586786) then
		Player.Character.Humanoid.WalkSpeed = 40
	end
end)

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if Marketplace:UserOwnsGamePassAsync(Player.UserID, 9586786) then
			Playerz.Character.Humanoid.WalkSpeed = 40
		end
	end)
end

5 comments

0

what is "Playerz"

0

i forgot to change playerz to player

0

but that is not the cause of the problem.

0

try useing this script to check if the player owns the gamepass

0

local MarketPlaceService = game:GetService"MarketPlaceService" local function ownsgamepass(userid,gamepassid) local s,res = pcall(MarketPlaceService.UserOwnsGamePassAsync,MarketPlaceService,userid,gamepassid) if not s then res = false end return res end

2 answers

local id = YOUR_ID_HERE
 
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and ido == id then
        plr.Character.Humanoid.WalkSpeed = 30 --player walk speed (change if you want it higher
    end
end)
 
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
            char.Humanoid.WalkSpeed = 30
        end
    end)
end)
--Make a gamepass and copy and paste ID into the top

Try this, it should prompt them to buy a speed gamepass then give them speed

3 comments

0

i changed it a little bit and when I try reseting, the chars Walkspeed goes back to 16.

0

why is their a z after player

0

maybe you should make it check if the player who joined owns the gamepass

Could it be because of your connection? If yes then instead of CharacterLoaded use CharacterAppearanceLoaded as it's better.

2 comments

0

I tried to use CharacterAppearanceLoaded, it didn't work.

0

Well then instead of character.Humanoid try to use character:WaitForChild"Humanoid" everywhere, maybe that will help (again i dunno the reason but if it's in wifi then this should help).

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