This is the first script (localsript) which works perfectly
local player = game.Players.LocalPlayer local UIS = game:GetService("UserInputService") local deboune = false UIS.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then if deboune == true then return end deboune = true game.ReplicatedStorage.Controls.ShiftCharge:FireServer(Input) wait(.3) deboune = false end end)
this is the script in which im having some trouble with. i got rid of lots of the script to shorten it to the important bits
local user = game:GetService("UserInputService") game.ReplicatedStorage.Controls.ShiftCharge.OnServerEvent:Connect(function(plr, Input) repeat x = x + 1 wait(1) until user.InputEnded --Input.UserInputState == Enum.UserInputState.End end)
Input.UserInputState == Enum.UserInputState.End
works in studio as there is no client-server boundary but in game it doesnt work.
user.InputEnded doesnt work in studio and the game eventhough im still pressing the key.
Sorta interesting, however here is a way you can do it (Keep in mind these need to be local script)
local player = game.Players.LocalPlayer local UIS = game:GetService("UserInputService") local keydown = false UIS.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then keydown = true end end) UIS.InputEnded:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then keydown = false end end while true do wait(1) if keydown then -- whatever you want to repeat while the key is down end end
Here is how it works: When the input starts, it sets a variable to true. The loop that runs then realizes that a key is down and runs. When the key stops being held down, it changes the variable.
I tried doing this using bool values so whenever it equals true, the value starts adding. Just as Commander was explaining.
Local script:
local player = game.Players.LocalPlayer local UIS = game:GetService("UserInputService") local deboune = false UIS.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.LeftShift then if deboune == true then return end deboune = true player.Clicking.Value = true game.ReplicatedStorage.Controls.ShiftCharge:FireServer(Input) wait(.3) deboune = false end player.Clicking.Value = false end)
Local script:
local user = game:GetService("UserInputService") local plr = game.Players.LocalPlayer -- Creating bool value local Boolvalue = Instance.new("BoolValue") Boolvalue.Parent = plr Boolvalue.Name = "Clicking" local NumberValue = Instance.new("NumberValue") NumberValue.Parent = plr NumberValue.Name = "Example" NumberValue.Value = 0 game.ReplicatedStorage.Controls.ShiftCharge.OnServerEvent:Connect(function(plr) while wait(.2) do spawn(function() if Boolvalue.Value == true then plr.Example.Value = plr.Example.Value + 1 end end) end end)