InputEnded firing twice?

Its time like this when I absolutely despise coding

Im following a combat system playlist tutorial.

Edit: It seems like the InputEnded function is firing twice when i placed a print statememnt before the remote was fired i cannot find anything about InputEnded only about InputBegan on this problem. I will try to switch to InputBegan instead of InputEnded.

This is a local script under StarterCharacterScripts

UIS.InputEnded:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end
	
	if input.KeyCode == Enum.KeyCode.One then
		WeldWeapon:FireServer("Equip/Unequip")
	end
end)

This is the server script where the event is being received

WeldWeapon.OnServerEvent:Connect(function(plr, action)
	local char = plr.Character
	local hum = char.Humanoid
	local torso = char.Torso
	local leftArm = char["Left Arm"]

	if action == "Equip/Unequip" and not char:GetAttribute("Equipped") then -- equipping
		print(action)
		print(char:GetAttribute("Equipped"))
		print("equipping")
		char:SetAttribute("Equipped",true)
		
		welds[plr].Part0 = leftArm
		welds[plr].C1 = WeaponsWeld.Scythe.HoldingWeaponWeld.C1

	elseif action == "Equip/Unequip" and char:GetAttribute("Equipped") then -- unequipping
		print(action)
		print(char:GetAttribute("Equipped"))
		print("unequipping")
		char:SetAttribute("Equipped",false	)

		welds[plr].Part0 = torso
		welds[plr].C1 = WeaponsWeld.Scythe.IdleWeaponWeld.C1
		

	end
end)

equipping and unequipping are being printed at the same time when I press “1” and that is the main problem

The “Equipped” attribute is set to false above this function when the character is added i didnt include it because this would get too long

2 Likes

Okay so I took the long way and duplicated everything into a new game and started deleted things to see what the problem was. It seems that the problem is this local script that i copied from somewhere in dev forum to create a viewport frame of the player which I used for my inventory frame.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local ViewCamera = Instance.new("Camera")
ViewCamera.Parent = script.Parent.ViewportFrame
ViewCamera.CFrame = CFrame.new(0, 0, 0)
script.Parent.ViewportFrame.CurrentCamera = ViewCamera


repeat wait(.1) until game:IsLoaded()

Character.Archivable = true



local ClonedCharacter  = Character:Clone()
CurrentCharacter = ClonedCharacter
ClonedCharacter.Parent = script.Parent.ViewportFrame.WorldModel
ClonedCharacter.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
ClonedCharacter:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 0, -9.5), Vector3.new(0, 0, 0)))


function LoadCharacter()
	wait(2)
	local ClonedCharacter  = Character:Clone()
	CurrentCharacter = ClonedCharacter
	ClonedCharacter.Parent = script.Parent.ViewportFrame.WorldModel
	ClonedCharacter.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	ClonedCharacter:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 0, -9.5), Vector3.new(0, 0, 0)))
end


local ReloadEvent = game.ReplicatedStorage.Remotes:WaitForChild("ReloadEvent")

ReloadEvent.OnClientEvent:Connect(function()
	LoadCharacter()
end)

if some intelligent person can please tell me why this script is making my input ended firing twice it would be much appreiciated.

1 Like

Hey, with only this piece of code i can’t really point out precisely the issue but if your InputEnded event fires twice it means that you wrote it under a function that is fired twice so when your InputEnded is triggered, it prints twice. It could also be under a RemoteEvent that you fired twice. I hope this will help you a little bit in fixing this if youd din’t fix it yet.

2 Likes

You are cloning the character so the scripts under StarterCharacterScripts get re-executed
(this is the only possible cause I can think of)

2 Likes

The event is maybe fired twice make sure the serverscript is inside ServerScriptService. Or if it is inside you can send me the script where the event is fired. Also add a print at the start to see how many times it gets executed.

2 Likes

Was not expecting three replies in one day on a post i made four days ago lol.

this is the part where the event is fired it is a local script under StarterCharacterScripts

yeah this probably was the issue Im just going to see if i can make a work around later

Yeah i deleted the script and everything works fine I will revamp it later

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