UserInputService saves input?

I’m not sure how to explain but when I press the specified key and the event fires, it seems to save the input when the requirements are met?

Basically:

  1. I press the key (leftctrl)
  2. I switch the teams
  3. I enable a required boolValue in my character (on the server)
  4. My character does the actions defined in the script without any input after

Is there something to prevent this?

ServerScript (inside char):

local players = game:GetService("Players")

local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local inputEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("ActorInput")

local id1 = 18126945100
local id2 = 18126957847
local id3 = 18126959536


local getDown = ("rbxassetid://"..id1)
local lay = ("rbxassetid://"..id2)
local getUp = ("rbxassetid://"..id3)

local getdown = Instance.new("Animation")
getdown.AnimationId = getDown
local L = Instance.new("Animation")
L.AnimationId = lay
local getup = Instance.new("Animation")
getup.AnimationId = getUp

local animator = humanoid:WaitForChild("Animator")

local GetUpAnim = animator:LoadAnimation(getup)
local LayAnim = animator:LoadAnimation(L)
local GetDownAnim = animator:LoadAnimation(getdown)

local surrendered = false

inputEvent.OnServerEvent:Connect(function(plr, input, mouseInput)
	if plr.Neutral then return end
	if plr.Team ~= game:GetService("Teams")["Test Subject"] then return end
	local inputToUse = string.lower(input)
	if inputToUse == "leftcontrol" or "rightcontrol" then
		if plr.Character == char then
			if plr.Team == game:GetService("Teams")["Test Subject"] then
				if char:FindFirstChild("Terminate").Value == true then
					local check = char:GetDescendants()
					for _, v in pairs(check) do
						if v:IsA("Part") then
							v.Anchored = true
						end
					end
					if surrendered == false then
						humanoid.WalkSpeed = 0
						humanoid.JumpHeight = 0
						GetDownAnim:Play()
						GetDownAnim.Ended:Wait()
						surrendered = true
						char:FindFirstChild("Terminate").Value = false
						LayAnim:Play()
					elseif surrendered == true then
						LayAnim:Stop()
						GetUpAnim:Play()
						GetUpAnim.Ended:Wait()
						for _, v in pairs(check) do
							if v:IsA("Part") then
								v.Anchored = false
							end
						end
						humanoid.WalkSpeed = 18
						humanoid.JumpHeight = 7.2
						surrendered = false
						char:FindFirstChild("Terminate").Value = true
					end
				end
			end
		end
	end
end)

Local Script (inside starterplrscripts):

local UIS = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("ActorInput")


UIS.InputBegan:Connect(function(input, eve)
	if eve then return end
	local otherInput = input.UserInputType
	event:FireServer(input.KeyCode.Name, otherInput)
end)
1 Like

It doesn’t save your inputs; the issue is that you never change the boolValue when the key is released, thus means that you are saving the inputs. Try this and see if it works:

UIS.InputEnded:Connect(function(input, eve)
	if eve then return end
	local otherInput = ""
	event:FireServer("", otherInput)
end)
1 Like
UIS.InputBegan:Connect(function(input, eve)
	if eve then return end
	local otherInput = input.UserInputType
	event:FireServer(input.KeyCode.Name, otherInput)
end)

UIS.InputEnded:Connect(function(input, eve)
	if eve then return end
	local otherInput = ""
	event:FireServer("", otherInput)
end)

Like this?

Seems like it did not work, the moment I switched to client - it immediately ran the code.

Does it give any errors? Also, using print debugging, which part doesn’t work!

1 Like

The part where it is meant to erase the input does not work.

As of the moment I was writing this, I realized - otherInput was a variable I set to know when the mouse is being pressed. We need to change input somehow.

You can try setting input to nil.

input = ""

That way, it should erase input completely. Are there any errors by the way?

1 Like

No errors. I’ll try this out when I can, currently had to go off my computer.

Sorry for the late reply.
It did not work - Once again, no errors.
Script:

UIS.InputBegan:Connect(function(input, eve)
	if eve then return end
	local otherInput = input.UserInputType
	event:FireServer(input.KeyCode.Name, otherInput)
end)

UIS.InputEnded:Connect(function(input, eve)
	if eve then return end
	local otherInput = ""
        input = ""
	event:FireServer("", otherInput)
end)

Update: Whenever a script should work, it doesnt. I feel so jolly.

I’ve fixed my issue using ChatGPT. Apparently, in my server script, the input was being considered true one way or another.

1 Like

Sorry I couldn’t help; I was a little busy. Great job on fixing the problem, and good luck on your project :wink:

1 Like

Thank you!

Only major difficulties ahead are probably guns and other stuff.
I’ll try to stay motivated though!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.