Reasons my script wont work?

Walkspeed gamepass script, not sure why it isn’t working. I followed an AlvinBlox tutorial for this.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if game.MarketplaceService:PlayerOwnsAsset(player,18375850) then 
			character.Humanoid.WalkSpeed = 24 
		end
	end)
end)
1 Like
MarketplaceService:UserOwnsGamePassAsync(player.UserId, 18375850)

Also, is it a gamepass? The code above is for a gamepass.

1 Like

You’re probably using an outdated tutorial, the similar answer was found here:

3 Likes

Add a pcall() :grinning_face_with_smiling_eyes:

2 Likes

pcall does not solve the issue in this context. They only shield the scripts from completely breaking because of an endpoint failure. Although not exactly the solution, it would be trivial and optional to apply pcall.

1 Like

That might work but you’d wanna do it like this then

local ASSET_ID = 30331986
local ASSET_NAME = "Midnight Shades"
 
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset
 
Players.PlayerAdded:Connect(function (player)
	local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, ASSET_ID)
	if doesPlayerOwnAsset then
		print(player.Name .. " owns " .. ASSET_NAME)
	else
		print(player.Name .. " doesn't own " .. ASSET_NAME)
	end
end)

I mean do it too see the error

1 Like

Although, it probably is outdated, on the roblox wiki itself it uses a pcall. But that will not fix it I bet.

local GamepassId = 12345678 -- ID here

local MarketPlaceService = game:GetService("MarketPlaceService")

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        if MarketPlaceService:UserOwnsGamepassAsync(player.UserId,GamepassId) then
            Character.Humanoid.WalkSpeed = 0 -- Number Here
        end
    end)
end)
1 Like

Also, it isn’t for gamepass or developer product

  • This method should not be used for game passes, since they use a separate ID system. Legacy game passes that still depend on an asset ID should use GamePassService:PlayerHasPass (which is old, don’t use.) instead of this method.

  • This method cannot be used to check for developer products since they can be purchased multiple times but not owned themselves. Use a GlobalDataStore to save when a developer has bought a developer product instead.

I am getting this error using your script

UserOwnsGamepassAsync is not a valid member of MarketplaceService “MarketplaceService” - Server - WalkspeedScript:7

1 Like

make sure you put a colon “:” instead of a dot “.” before UserOwnsGamePassAsync()

1 Like
game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Char)
        if game.MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Here) then  --- Place ID where i said here
            Char.Humanoid.WalkSpeed = 0
        end
    end)
end)

That should work but why not place a script in PlayerCharacterScripts

local player = game.Players:GetPlayerFromCharacter(script.Parent)
local id = 00000

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
     Char.Humanoid.WalkSpeed = 0
end

That’s a typo, apparently. The correct name should be UserOwnsGamePassAsync, note the capitalized P.

1 Like

Sure was a typo, it works now. Weird why it didn’t flag it.

I edited your script a bit it worked for me in my game I put it in StarterScriptService with a Script and Used this Code that I edited from yours.

local MPS = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if MPS:UserOwnsGamePassAsync(player.UserId,4583776) then 
			character.Humanoid.WalkSpeed = 24 
		end
	end)
end)

1 Like