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

How can i fix this problem with this local sprint script i am editing?

Asked by 6 years ago
Edited 6 years ago

I was trying to edit SprintScript to make it enable effects for local player. It works in studio, but it doesnt work in game (Effects dont appear, it only changes WalkSpeed,FoV and JumpPower, puts sprint feature into infinite loop after i press shift while i am in game)

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 = (160)
            wait()
        end
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 248
        game.Players.LocalPlayer.Character.Humanoid.JumpPower = 250
        game.Workspace.CurrentCamera.CC.Enabled = true
        game.Workspace.CurrentCamera.Blur.Enabled = true
        game.Players.LocalPlayer.PlayerGui.Sound:Play()
        game.Players.LocalPlayer.PlayerGui.Peace:Stop()
        game.Players.LocalPlayer.PlayerGui.Run.Enabled = true
        repeat wait () until running == false
        keyConnection:disconnect()
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 12
        game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50
        game.Workspace.CurrentCamera.CC.Enabled = false
        game.Workspace.CurrentCamera.Blur.Enabled = false
        game.Players.LocalPlayer.PlayerGui.Run.Enabled = false
        game.Players.LocalPlayer.PlayerGui.Sound:Stop()
        game.Players.LocalPlayer.PlayerGui.Peace:Play()
        for i = 1,5 do
            game.Workspace.CurrentCamera.FieldOfView = (70)
            wait()
        end
    end
end)

How can I fix it?

2
First of all, mouse.KeyDown is deprecated. You should be using UserInputService. Second of all, is there any errors on the output? ObscureIllusion 352 — 6y
0
There is no errors in output, Now i will try to convert it into the UserInputService Unity_456 47 — 6y
0
I have tried to do it, but with my knowing of my scripting i only broke it worse. Unity_456 47 — 6y
0
Wasted 2 hours on trying to make it work in game, nothing works. Unity_456 47 — 6y
0
Did you enable filtering, you'll need to turn it on for local effects to work. LifeInDevelopment 364 — 6y

Answer this question