I have a sword script that has one major glitch : the scripts only work on the tool most recently added to the backpack. Here is the linked local script where the error occurs(there are no actual errors in the output)
local A = true
local equip = false
local tool = script.Parent
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin and A == false and equip == true then--the if statement falters on the 'and equip == true', it treats it as false if the equipped tool isn't the most recently added
print(script.Parent)
A = true
local rs = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local name = player.Name
local o = name.."swordout"
local f = rs.PlayerStuff
local so = f:FindFirstChild(o)
so:FireServer()
tool.Handle.SlashSound:Play()
wait(1)
A = false
end
end
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.Q)
tool.Equipped:Connect(function ()
equip = true-- it is changed every time
A = false
end)
tool.Unequipped:Connect(function()
equip = false
A = true
end)
