Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my gamepass sprint speed script not work?

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 = 30
		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)

1 answer

✓ Accepted answer

Okay firstly everything below "Some variables" needs to be in a local script, then use a remoteevent to change the walkspeed.

Create a RemoteEvent in ReplicatedStorage called "runScript"

Serverscript

local MarketplaceService = game:GetService("MarketplaceService")
local gamepassId = 0000000
local speed = 30

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if MarketplaceService.UserOwnsGamepassAsync(plr.UserId,gamepassId) then
			speed = 40
		end
	end)
end)

game.ReplicatedStorage.runScript.OnServerEvent:Connect(function(Player, status)
	if status == true then
		Player.Character.Humanoid.WalkSpeed = speed
	else
		Player.Character.Humanoid.WalkSpeed = 16
	end
end)

Localscript

local ContextActionService = game:GetService("ContextActionService")

local function heBeRunnin(actionName, inputState, inputObj)
	if inputState == Enum.UserInputState.Begin then
		for i = 1,5 do
			workspace.CurrentCamera.FieldOfView = (70+(i*2))
			wait()
		end
		game.ReplicatedStorage.runScript:FireServer(true)
	elseif inputState == Enum.UserInputState.End then
		for i = 1,5 do
			workspace.CurrentCamera.FieldOfView = (80-(i*2))
			wait()
		end
		game.ReplicatedStorage.runScript:FireServer(false)
	end
end

ContextActionService:BindAction("RunningAction", heBeRunnin, false, Enum.KeyCode.Shift)

5 comments

0

can I have an example?

0

Try that

0

ok, thanks

0

should the local script be the children of the script?

0

I'd put it in either StarterPlayerScripts or ReplicatedFirst

This discussion is preserved as it was. New answers, comments, and votes are closed.