Melee Script Not Working

local Tool = script.Parent

local Animation = script.Parent:WaitForChild("Attack")

local AnimationId = {
	Animation1 = "rbxassetid://14161281319",
	Animation2 = "rbxassetid://14161288180",
	Animation3 = "rbxassetid://14161290360",
	Animation4 = "rbxassetid://14161292365",
	Animation5 = "rbxassetid://14161301152"
}

local Debounce = true

local DamageRarity = {
	{5,70},
	{8,15},
	{10,10},
	{12,5},
}

function DamageChance() 
	if DamageRarity then
		local types = {}
		local prng = Random.new()
		for a,b in ipairs(DamageRarity) do
			local r = b[2]
			for t=1,r*100 do
				table.insert(types,b[1])
			end
		end

		return types[prng:NextInteger(1,#types)]
	end

	return 0
end



function Attack(Player, Enemy)
	local Humanoid = Tool.Parent:WaitForChild("Humanoid") 
	local Damage = DamageChance()
	Enemy.Humanoid.Health -= Damage
	print(Damage)
	local FightUtils = require(game:GetService("ServerScriptService").player:WaitForChild("FightUtils"))
	FightUtils.Knockback(Player, Enemy)
	Tool.Handle.PunchSound:Play()
end

Tool.Activated:Connect(function()
	if Debounce == true then
		Debounce = false
		Animation.AnimationId = AnimationId["Animation"..math.random(1,5)]
		Tool.Parent.Humanoid:LoadAnimation(AnimationId):Play()
		script.Swing:Play()
		Tool.Handle.Trail.Enabled = true
		Tool.Parent.Humanoid.WalkSpeed = 3
		Tool.Parent.Humanoid.JumpPower = 0
		for _, Enemy in pairs(game:GetService("Workspace").Enemies:GetChildren()) do
			if (Tool.Handle.Position - Enemy.HumanoidRootPart.Position).Magnitude <= 5 then
				Attack(Tool.Parent, Enemy)
			end
		end
		task.wait(0.4)
		Tool.Parent.Humanoid.WalkSpeed = 7
		Tool.Parent.Humanoid.JumpPower = 15
		Tool.Handle.Trail.Enabled = false
		Debounce = true
	end
end)

No Errors pop up neither does it work.

1 Like

Is the script a LocalScript or a Script?

1 Like

its a script

charrrrrr

as in the animations dont play or the tool doesnt do any damage at all

1 Like

The tool activation ion know why

uhhhhh i think its because debounce was set as true from the start

your conditional makes it so it doesnt do anything but it still recieves the event firing
just remember that the variable is the problem not the conditional

more specifically the value itself, just set the value to false and you solved it

no because if it equals false the if statement wont be true i got rid of the debounce, it doesnt do anything

also based on the meaning of debounce i suggest you do if not Debounce and make the starting value false so as its negated it turns true, also i think the variable Animation at the start is probably yielding so either you make the animation itself or name it Attack or use second optional variable for :WaitForChild() timeout in seconds, for example :WaitForChild("Part", 1) will time out in 1 second if it cannot find Part

1 Like

It was a incorrect variable that was the problem :man_facepalming: i barely noticed

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