I've been trying to make a walkspeed gamepass and It seems to not be working, I've made a script but whenever I play my game it won't work, please help?
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if game.MarketplaceService:PlayerOwnsAsset(player,4653124) then character.Humanoid.WalkSpeed = 36 end end) end)
It would be great if you could help me out on this, any recommendations?
You're using MarketplaceService:PlayerOwnsAsset()
with a gamepass id, while that function only accepts the asset id.
Each gamepass has both asset id and gamepass id. Gamepass id is usually shorter than its asset id.
If you want to check if a player owns a gamepass by its gamepass id, you need to use MarketplaceService:UserOwnsGamePassAsync()
, like this:
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 4653124) then
But you can also obtain the asset id of your gamepass to be able to use it with PlayerOwnsAsset()
:
if game:GetService("MarketplaceService"):PlayerOwnsAsset(player.UserId, 1929538711) then --1929538711 is your gamepass's asset id
So, with some corrections, your code should look like this:
local passOwners = {} --add to this table if they buy it in game, so they don't have to rejoin game.Players.PlayerAdded:Connect(function(plr) passOwners[plr.Name] = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, 4653124) plr.CharacterAdded:Connect(function(char) if passOwners[plr.Name] then char:WaitForChild("Humanoid").WalkSpeed = 36 end end) end)