Can anyone explain to me why this is happening?
local uis = game:GetService("UserInputService") uis.InputBegan:connect(function(input,gp) if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then if input.KeyCode == Enum.KeyCode.Left then script.Parent.Value = -1 end end end) uis.InputEnded:connect(function(input,gp) if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then if input.KeyCode == Enum.KeyCode.Left then script.Parent.Value = 0 end end end) uis.InputBegan:connect(function(input,gp) if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then if input.KeyCode == Enum.KeyCode.Right then script.Parent.Value = 1 end end end) uis.InputEnded:connect(function(input,gp) if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then if input.KeyCode == Enum.KeyCode.Right then script.Parent.Value = 0 end end end)
It all depends on where you have placed the Local Script.
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
1. A Player's Backpack, such as a child of a Tool
2. A Player's Character model
3. A Player's PlayerGui
4. A Player's PlayerScripts
5. The ReplicatedFirst service
Additionally, you should really only be using one RBXScriptSignal for each event like so:
local uis = game:GetService("UserInputService") uis.InputBegan:Connect(function(input,gp) if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then if input.KeyCode == Enum.KeyCode.Left then script.Parent.Value = -1 end if input.KeyCode == Enum.KeyCode.Right then script.Parent.Value = 1 end end end) uis.InputEnded:Connect(function(input,gp) if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then if input.KeyCode == Enum.KeyCode.Left then script.Parent.Value = 0 end if input.KeyCode == Enum.KeyCode.Right then script.Parent.Value = 0 end end end)