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

My script won't work and won't return any error to the output, I don't understand why?

Hey. I made a script that whenever a player presses V it will change his CameraMode. For some reason it won't work, and it won't return any error to the output. Here's my script, lines 29-40:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(isTyping, KeyCode)
	if not isTyping then
		if KeyCode.KeyCode == Enum.KeyCode.LeftShift then
			local players = game:GetService("Players")
			local localPlayer = players.LocalPlayer
			local character = localPlayer.Character
			local humanoid = character.Humanoid
			local speed = 19
			humanoid.WalkSpeed = tonumber(speed)
		end
	end
end)

UIS.InputEnded:connect(function(isTyping, KeyCode)
	if not isTyping then
		if KeyCode.KeyCode == Enum.KeyCode.LeftShift then
			local players = game:GetService("Players")
			local localPlayer = players.LocalPlayer
			local character = localPlayer.Character
			local humanoid = character.Humanoid
			local speed = 13
			humanoid.WalkSpeed = tonumber(speed)
		end
	end
end)

UIS.InputBegan:connect(function(isTyping, KeyCode)
	if not isTyping then
		if KeyCode.KeyCode == Enum.KeyCode.V then
			local localPlayer = game.Players.LocalPlayer
			if localPlayer.CameraMode == Enum.CameraMode.Classic then
				localPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
			elseif localPlayer.CameraMode == Enum.CameraMode.LockFirstPerson then
				localPlayer.CameraMode = Enum.CameraMode.Classic
			end
		end
	end
end)

I will make sure to accept the helpful answer!

2 comments

0

ok

0

I'm not sure v has this problem, but certain Enum.KeyCode values will return true for isTyping, because it's really gameProcessedEvent, and it might mean typing, mouseLock, leaderboard, backpack, etc. processed it

1 answer

✓ Accepted answer

It's because you have (isTyping, KeyCode). Please note that the order of the parameters do actually matter. The first parameter of this event is the Input and the next is gameProcessedEvent. So in your script, 'isTyping' is being assigned to the Input, and 'KeyCode' is being assigned to gameProcessedEvent. Just switch the parameters around and it should work.

1 comment

0

I will try it right now. If it will help I will accept your answer. Let me do it very quick.

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