so i was trying to make a combat system specifically playing the right animations
issue is that, when I press mouse button 1 , it runs the script twice, when I only want it to run once per mouse button 1 pressed. secondly no animations are playing, and there isn’t any error message
I have two scripts, a local and a module
local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local ListoFWeapons = {
"BasicSword",
"RengokuSword",
"PlaceHolder1",
}
local module = require(rs:WaitForChild("Modules").CombatSystemModule)
local CombatNum = 1
uis.InputBegan:Connect(function(input,e)
if e then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
for i,v in player.Character:GetChildren() do
if v.Name == "BasicSword" or v.Name == "RengokuSword" and v:IsA("MeshPart") then
print("this work")
module.CombatSystem(player,CombatNum)
CombatNum += 1
if CombatNum > 3 then
CombatNum = 1
end
end
end
end
end)
and the modulecript is
local module = {}
module.CombatSystem = function(player,CombatNum)
local char = player.Character
local hum = char:WaitForChild("Humanoid")
for i,v in game:GetService("ReplicatedFirst").Animations.KatanaM1s:GetChildren() do
if v.Name == CombatNum then
print(CombatNum)
local KatanaCombat = hum:LoadAnimation(v)
KatanaCombat:Play()
end
end
end
return module
local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local ListOfWeapons = {
"BasicSword",
"RengokuSword",
"PlaceHolder1",
}
local module = require(rs:WaitForChild("Modules").CombatSystemModule)
local CombatNum = 1
uis.InputBegan:Connect(function(input,e)
if e then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
for i,v in player.Character:GetChildren() do
if table.find(ListOfWeapons, v.Name) and v:IsA("MeshPart") then -- assuming this is the problem, as it may of let other MeshParts through
module.CombatSystem(player, CombatNum)
CombatNum += 1
if CombatNum > 3 then
CombatNum = 1
end
return
end
end
end
end)
ModuleScript
local module = {}
module.CombatSystem = function(player,CombatNum)
local char = player.Character
local hum = char:WaitForChild("Humanoid")
for i,v in game:GetService("ReplicatedFirst").Animations.KatanaM1s:GetChildren() do
if tonumber(v.Name) == CombatNum then -- you were comparing a string to a number, which led it to believe that they were not equal
local KatanaCombat = hum:LoadAnimation(v)
KatanaCombat:Play()
end
end
end
return module