I want to make my own fighting style that it will do damage when tool is activate. After I test, it look like it work properly. But when i unequipped, it still do damage. Or equip but not attacking, it still do damage.
Here is my script
local tool = script.Parent
repeat wait() until tool.plr.Value ~= nil
repeat wait() until tool.plr.Value.Character ~= nil
local plr = tool.plr.Value
local char = plr.Character
local hum = char.Humanoid
local idle = hum:LoadAnimation(tool.Idle)
tool.Equipped:Connect(function()
char.Animate.Disabled = true
idle:Play()
end)
tool.Unequipped:Connect(function()
char.Animate.Disabled = false
idle:Stop()
end)
tool.Activated:Connect(function()
if tool.Enabled == true and tool.Name == "Attack" then
tool.Enabled = false
tool.Name = "[ ... ]"
local num = math.random(1,3)
for _,attack in pairs(tool:GetChildren()) do
if attack.Name == "Attack" then
if attack.Style.Value == num then
local anim = hum:LoadAnimation(attack)
idle:Stop()
anim:Play()
if num == 1 then
char["Right Arm"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent ~= char then
if hit.Parent.Humanoid:FindFirstChild(char.Name.."Attack"..num) then
else
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - script.PunchDamage.Value
local model = Instance.new("Model")
model.Parent = hit.Parent.Humanoid
model.Name = char.Name.."Attack"..num
wait(0.5)
model:Destroy()
end
end
end
end)
elseif num == 2 then
char["Left Arm"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent ~= char then
if hit.Parent.Humanoid:FindFirstChild(char.Name.."Attack"..num) then
else
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - script.PunchDamage.Value
local model = Instance.new("Model")
model.Parent = hit.Parent.Humanoid
model.Name = char.Name.."Attack"..num
wait(0.5)
model:Destroy()
end
end
end
end)
elseif num == 3 then
char["Right Leg"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent ~= char then
if hit.Parent.Humanoid:FindFirstChild(char.Name.."Attack1"..num) then
else
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - script.KickDamage.Value
local model = Instance.new("Model")
model.Parent = hit.Parent.Humanoid
model.Name = char.Name.."Attack1"..num
wait(0.5)
model:Destroy()
end
end
end
end)
char["Left Leg"].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent ~= char then
if hit.Parent.Humanoid:FindFirstChild(char.Name.."Attack2"..num) then
else
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - script.KickDamage.Value
local model = Instance.new("Model")
model.Parent = hit.Parent.Humanoid
model.Name = char.Name.."Attack2"..num
wait(0.5)
model:Destroy()
end
end
end
end)
end
anim.Stopped:Connect(function()
tool.Name = "Attack"
idle:Play()
tool.Enabled = true
end)
end
end
end
end
end)

1 comment
You could simplify the script by making each Touched function calling a sub program.