GamePass wont work after reseting or leaving and joining again

Hello Devs! :wave:

I created a gamepass called “Speed GamePass”, and it works. But whenever the player leaves the game or resets… They will loose their speed. How can I fix this? Any response is appreciated! :slight_smile:

Code:

local speedGamePassImageButton = script.Parent
local speedGamePassLabel = script.Parent.SpeedGamePassLabel
local marketPlace = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamePassID = 15190401

speedGamePassImageButton.MouseButton1Up:Connect(function()
	marketPlace:PromptGamePassPurchase(player, gamePassID)
	
	marketPlace.PromptGamePassPurchaseFinished:Connect(function(player, ID, wasBought)
		if wasBought and ID == gamePassID then
			player.Character:WaitForChild("Humanoid").WalkSpeed = 200
			speedGamePassLabel.Text = "Successfully bought speed gamepass!"
			wait(3)
			speedGamePassLabel.Text = "If you buy the speed gamepass, you will be granted extra speed!"
		end
	end)
end)



game.Players.PlayerAdded:Connect(function(player)
	local hasSpeedGamePass = marketPlace:UserOwnsGamePassAsync(player.UserId, gamePassID)
	if hasSpeedGamePass then
		player.Character:WaitForChild("Humanoid").WalkSpeed = 200
	end
end)
1 Like

This is because you are only utilizing PlayerAdded. You should nest a CharacterAdded event in that PlayerAdded event so that every time the character respawns, it will get the speed boost.

2 Likes

Hello! You can use the Player.CharacterAdded event so everytime the character loads you’ll change the WalkSpeed. Would be something like this: (Haven’t tested)

game.Players.PlayerAdded:Connect(function(player)
	local hasSpeedGamePass = marketPlace:UserOwnsGamePassAsync(player.UserId, gamePassID)
	if hasSpeedGamePass then
        --Make a characterAdded conection
        player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.WalkSpeed = 200
        end)
	end
end)
2 Likes

I reset, and I still have the same 16 walkspeed. And when I leave the game and join back, I still have 16 walkspeed.

It was a simple error, I forgot to add a " ) " in the end for the connection.

I fixed the script and you should try it now, remember to always debug it yourself so you catch those minor errors.

No, I fixed the errors before you edited it. And I didn’t get any errors in the output. The speed is still the same.

Try debugging the script, such as putting prints so you know if the connections ever fire, try seeing what’s the Humanoid.WalkSpeed right after the connection triggers.

The walkspeed is still the same. And I wrote :

game.Players.PlayerAdded:Connect(function(player)
	local hasSpeedGamePass = marketPlace:UserOwnsGamePassAsync(player.UserId, gamePassID)
	if hasSpeedGamePass then
		print(player.Name .. " owns the gamepass")
		--Make a characterAdded conection
		player.CharacterAdded:Connect(function(Character)
			Character.Humanoid.WalkSpeed = 200
		end)
	end
end)

And nothing printed in the output…

That means the hasSpeedGamePass boolean is not true, which means the connection will never be made. Check if the GamepassID is correct and if you are using the correct reference for MarketPlaceService, you can also check if hasSpeedGamePass is actually “false” and not nil.

Update: I tested the same script in-game and it worked completly fine for me.

It’s printing false in the output when I bought the gamepass

And I tested it in game and actually bought it. And I was able to keep buying it somehow…

By in-game do you mean in an actual game or in Roblox Studio?

UserOwnsGamePassAsync being false right when the player bought gamepass seems to be a Roblox issue, as seem on this threads:

But it should be fine after some seconds.

I have no idea about this, I’ve managed to find a thread that seemed to have this same issue, maybe it can help you:

In the actual game and in roblox studio. They both don’t work and keep printing in the output false but I did buy the gamepass…

Code:

local speedGamePassImageButton = script.Parent
local speedGamePassLabel = script.Parent.SpeedGamePassLabel
local marketPlace = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamePassID = 15190401

speedGamePassImageButton.MouseButton1Up:Connect(function()
	marketPlace:PromptGamePassPurchase(player, gamePassID)
	
	marketPlace.PromptGamePassPurchaseFinished:Connect(function(player, ID, wasBought)
		if wasBought and ID == gamePassID then
			print(marketPlace:UserOwnsGamePassAsync(player.UserId, gamePassID))
			player.Character:WaitForChild("Humanoid").WalkSpeed = 200
			speedGamePassLabel.Text = "Successfully bought speed gamepass!"
			wait(3)
			speedGamePassLabel.Text = "If you buy the speed gamepass, you will be granted extra speed!"
		end
	end)
end)



game.Players.PlayerAdded:Connect(function()
	local hasSpeedGamePass = marketPlace:UserOwnsGamePassAsync(player.UserId, gamePassID)
	if hasSpeedGamePass then
		print(player.Name .. " owns the gamepass")
		--Make a characterAdded conection
		player.CharacterAdded:Connect(function(Character)
			Character.Humanoid.WalkSpeed = 200
		end)
	end
end)

Output:

Screenshot (77)

Oh wait I think I know the problem. I’m not sure if this will run any different then what you already did but on my game it works, so maybe it will here.

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 = 50
		end
	end)
end)

What you did was you made a local Boolean variable that checks if the user owns the gamepass, and then using that value you made an if statement. In this script, if they own the gamepass then it instantly runs the script.

Doesn’t works somehow… :sad:

Instead of that variable id, did you put in your own gamepass id?

Yeah, and I changed ‘connect’ to an uppercase C.

I even tried to wrap it in a pcall and print the error, but it won’t print the error. It’s just printing false and saying I don’t have the gamepass