Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why does my gamepass sprint speed script not work?

Asked by
iHavoc101 127
4 years ago
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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
can I have an example? iHavoc101 127 — 4y
0
Try that MachoPiggies 526 — 4y
0
ok, thanks iHavoc101 127 — 4y
0
should the local script be the children of the script? iHavoc101 127 — 4y
0
I'd put it in either StarterPlayerScripts or ReplicatedFirst MachoPiggies 526 — 4y
Ad

Answer this question