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

How do I make the player run faster if they have a pass?

Asked by
iHavoc101 127
5 years ago
Edited 5 years ago

The parent is a script called"SprintScript Importer":

function onPlayerEntered(player)
    repeat wait () until player.Character ~= nil
    local s = script.SprintScript:clone()
    s.Parent = player.Character
    s.Disabled = false
    player.CharacterAdded:connect(function (char)
        local s = script.SprintScript:clone()
        s.Parent = char
        s.Disabled = false      
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

The child is a local script call "SprintScript":

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)
0
Use a code block. pidgey 548 — 5y
0
iHavoc, the next time you ask this question, please highlight all your code then click on the Lua button instead of the >. It makes your code much easier to read so we can help you. beeswithstingerss 41 — 5y
0
ok iHavoc101 127 — 5y

1 answer

Log in to vote
0
Answered by
vkax 85
5 years ago

There's no need to clone a local script, simply just check once the player joins the game.

local marketplaceService = game:GetService("MarketplaceService")
local gamepassId = 0 -- your gamepass ID here
local speed = 25 -- set to whatever walking speed you want

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

Answer this question