This is kinda hard for me to explain, but basically, I have this local script where when I press or let go of left shift, it fires my remote event. When I press left shift it fires my remote event with an argument of true. When I let go of left shift it fires my remote event with argument of false.
On my server script where I have the OnServerEvent function, I have a while loop which is supposed to run only when the parameter is true, (so when I press left shift), except it keeps on running when I let go of left shift. Does anyone know why? Any help would be appreciated.
Local Script ----
local UIS = game:GetService("UserInputService")
local sprintEvent = script.Parent:WaitForChild("Sprint")
UIS.InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
sprintEvent:FireServer(true)
end
end)
UIS.InputEnded:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
sprintEvent:FireServer(false)
end
end)
Server Script ----
local sprintEvent = script.Parent:WaitForChild("Sprint")
sprintEvent.OnServerEvent:Connect(function(player,switch)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
while(switch) do
wait(1)
print("Sprinting")
end
if switch == false then
print("Not Sprinting")
end
end)
The while loop keeps on running when I let go of left shift, but the switch parameter should be false

1 comment
Hi! I did something similar to what u said, and I got it to work. Thank you!