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

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

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

15 comments

0

what is the error?

0

kingdom5 thats what im trying to find out dude. I think it deals with capitilization error cause thats what roblox said.

0

^ I’m a bit confused. Are you saying there’s an error or not? If so, can you please post the full error?

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.

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

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

0

kingdom5 thanks! Reply as a answer so i can mark you correct

2

shouldn't it be workspace.CurrentCamera?

1

workspace.CurrentCamera is preferable but both should work (Camera is the default name of the CurrentCamera)

0

set the walkspeed to like 20 you are only adding one

1

why does this have -6

0

YOOOOOOOOOOOOOOOOO WHEREs GOULSTEM, I DIDNT SEE HIM IN 2 YEARS Brah, u just got an upvote

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.""

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.

0

holy heck

1 answer

✓ Accepted answer

####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().

3 comments

0

Spamming shift will cause multiple threads to be created simultaneously, and they will start to interfere with eachother without a debounce.

0

Thank you for letting me know, though it should be up to OP to add one or not.

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 ;)

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