local marketplaceService = game:GetService("MarketplaceService")
local gamepassId = "gamepass" -- my gamepass id
local speed = 30 

game.Players.PlayerAdded:Connect(function(player)
	repeat wait() until player.Character
		if (marketplaceService:PlayerOwnsAsset(player, gamepassId) then
			local speed = 40
		return
	end
end)


-- Some variables
local mouse = game.Players.LocalPlayer:GetMouse()
local running = false

function getTool()	
	for _, kid in ipairs(script.Parent:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end


mouse.KeyDown:connect(function (key) -- Run function
	key = string.lower(key)
	if string.byte(key) == 48 then
		running = true
		local keyConnection = mouse.KeyUp:connect(function (key)
			if string.byte(key) == 48 then
				running = false
			end
		end)
		for i = 1,5 do
			game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
			wait()
		end
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = speed
		repeat wait () until running == false
		keyConnection:disconnect()
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
		for i = 1,5 do
			game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
			wait()
		end
	end
end)

2 comments

0

Updated my code, send me a DM on Discord MachoPiggies#3484 if it doesn't work. https://scriptinghelpers.org/questions/84542/why-does-my-gamepass-sprint-speed-script-not-work

0

because you made speed a local variable on line 8