Help with gamepass

I made this game pass to the increases players walk speed but when the player dies there speed goes back to the default walk speed.

local id = 9671338

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and id == ido then
		plr.Character.Humanoid.WalkSpeed = 40
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,id)then
		game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid").WalkSpeed = 40
	end
end)

Connect a function to when the player dies and make it check if they own the gamepass and reset their WalkSpeed to 40. (Sorry if that sounded confusing) You could use

local hum = game.Workspace:WaitForChild(plr.Name):WaitForChild("Humanoid")
hum.Died:Connect(function()
    hum.WalkSpeed = 40
end)

something like that.

Give them the speed when their character is added.
I made an example below.

local MarketplaceService = game:GetService('MarketplaceService')
local Players = game:GetService('Players')

local id = 9671338
local Speed = 40

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, ido, purchased)
	if purchased and id == ido then
		local character = plr.Character
		if character then
			local humanoid = character:FindFirstChild('Humanoid')
			if humanoid then
				humanoid.WalkSpeed = Speed
			end
		end
	end
end)

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, id)then
			local humanoid = character:FindFirstChild('Humanoid')
			if humanoid then
				humanoid.WalkSpeed = Speed
			end
		end
	end)	
end)

Hope this helps you understand.
CharacterAdded fires when their character is added, then we can modify the humanoid’s speed.

2 Likes

thanks for the help! :grinning: