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

Script wont work? My script is where you click shift to run. Its a code error. Please help!

Asked by 5 years ago
Edited by Goulstem 5 years ago

My script where you press shift to run wont work? Please fix.

game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        for i = 1,16 do
            wait()
            game.Workspace.camera.FieldOfView = game.Workspace.Camera.FieldOfView + 1.6
            game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 1
        end
    end
end)

game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        for i = 1,16 do
            wait()
            game.Workspace.Camera.FieldOfView = game.Workspace.Camera.FieldOfView - 1.6
            game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 1
        end
    end
end)

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function()
    game.Workspace.Camera.FieldOfView = 70
    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
    script.Disabled = true
end)

Edited: Tab your code correctly! ~Goulstem
0
what is the error? User#5423 17 — 5y
0
kingdom5 thats what im trying to find out dude. I think it deals with capitilization error cause thats what roblox said. Bowser_Films -50 — 5y
0
^ I’m a bit confused. Are you saying there’s an error or not? If so, can you please post the full error? User#20279 0 — 5y
0
Denny9876 i stated in the question there is a error. Why will i post a question if there was nothing wrong with it? I posted the whole script so i did post it. Bowser_Films -50 — 5y
View all comments (11 more)
0
on line 5 you have game.Workspace.camera it should be game.Workspace.Camera You should make variables to avoid repetition and these kind of mistakes User#5423 17 — 5y
0
You should alos not that there is not checks between each loop run so you are able to spam shift to break this code User#5423 17 — 5y
0
kingdom5 thanks! Reply as a answer so i can mark you correct Bowser_Films -50 — 5y
2
shouldn't it be workspace.CurrentCamera? theking48989987 2147 — 5y
1
workspace.CurrentCamera is preferable but both should work (Camera is the default name of the CurrentCamera) User#22604 1 — 5y
0
set the walkspeed to like 20 you are only adding one mattchew1010 396 — 5y
1
why does this have -6 User#19524 175 — 5y
0
YOOOOOOOOOOOOOOOOO WHEREs GOULSTEM, I DIDNT SEE HIM IN 2 YEARS Brah, u just got an upvote greatneil80 2647 — 5y
0
incapaz, it is because there is no description, just code. Not only that, but it goes against the community guidelines. They state: "Attempts should be your own work. Don't take a free model and expect us to fix it."" User#21908 42 — 5y
0
I highly doubt this is his own work, or if it is, it is only his work in that he edited the script he found somewhere. User#21908 42 — 5y
0
holy heck waifuSZN 123 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

Just a side note: If you get any output errors, post them on your question. We do not read minds. We want to help you, but you should help us first by giving us information.

Your problem seems to be on line 5:

game.Workspace.camera.FieldOfView = game.Workspace.Camera.FieldOfView + 1.6

You've spelt Camera as camera, yet camera doesn't exist according to what you said in the comments. Lua is case sensitive, so if capitalisation is off in some places it might not work. If you spell a name incorrectly it won't work.

Additionally, your code can be cleaned up. You use two for loops, when this could be put in a function and you call that function instead of writing duplicate loops:

local camera = workspace.CurrentCamera -- storing the local player's current camera in a variable

local function change_fov(number)
    for i = 1, 16 do
        wait()
        camera.FieldOfView = camera.FieldOfView + number
    end
end

And whenever you need to change the field of view you'd call change_fov with an argument of 1.6 or -1.6 like so:

change_fov(1.6)
-- or --
change_fov(-1.6)
-- Call the function when is it appropriate to do so. 

I also recommend that you have a variable for the local player as you were using that often as well. Also, you don't need to WaitForChild on the same object more than once, if the humanoid didn't exist at first, WaitForChild yielded (paused) until the humanoid was found.

And finally, RBXScriptSignal:connect() is deprecated, use RBXScriptSignal:Connect().

0
Spamming shift will cause multiple threads to be created simultaneously, and they will start to interfere with eachother without a debounce. Goulstem 8144 — 5y
0
Thank you for letting me know, though it should be up to OP to add one or not. User#19524 175 — 5y
1
It isn't an immediate issue compared to all of the fixes you've pointed out forsure, but it is essential to the program's functionality ;) Goulstem 8144 — 5y
Ad

Answer this question