So basically, I have a local script running inside a tool to play an animation and fire a remote event whenever I click and have the tool equipped, but instead what happens is that if I click and the tool isn't equipped, it fires the remote event. Could someone tell me why?
local UIS = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local Attack = ReplicatedStorage:WaitForChild("OnAttackSword") local char = plr.Character UIS.InputBegan:Connect(function(input, event) if input.UserInputType == Enum.UserInputType.MouseButton1 and script.Parent.Equipped then print("OK") game.ReplicatedStorage:FindFirstChild("OnAttackSword"):FireServer(char) script.Parent.Parent.Humanoid.WalkSpeed = 9 local animation = plr.Character.Humanoid:LoadAnimation(script.Parent.Attack1) animation:Play() wait(1.3) script.Parent.Parent.Humanoid.WalkSpeed = 16 end end)
Inputbegan fires the function whenever the usermade an input. With the if statement, your code fires, every click. This mean the code doesn't check whether the player has equiped the tool or not. There is actually a special event made for this that fires a function whenever the tool is equiped (.Activated)
local Tool = script.Parent Tool.Activated:Connect(function() -- your code end)