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

Character Added and prompt game pass purchase doesnt work?

Asked by 4 years ago

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
0
what is "Playerz" Raccoonyz 1092 — 4y
0
i forgot to change playerz to player AlexDoooYT 5 — 4y
0
but that is not the cause of the problem. AlexDoooYT 5 — 4y
0
try useing this script to check if the player owns the gamepass rainbowslime242 12 — 4y
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 rainbowslime242 12 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
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

0
i changed it a little bit and when I try reseting, the chars Walkspeed goes back to 16. AlexDoooYT 5 — 4y
0
why is their a z after player rainbowslime242 12 — 4y
0
maybe you should make it check if the player who joined owns the gamepass rainbowslime242 12 — 4y
Ad
Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago

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

0
I tried to use CharacterAppearanceLoaded, it didn't work. AlexDoooYT 5 — 4y
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). imKirda 4491 — 4y

Answer this question