Need help with combat critical system

I just started to make an combat critical system but i have no clue about that to do it

For example : when you hit a npc or another player theres a small chance(About 5%) to deal an critical hit which deals original damage * critical bonus damage
Is there a way to do it?

Also this is my set up

local Players = game:GetService("Players")

function OnCharAppearance(c)
	local critChance = Instance.new("NumberValue", c)
	critChance.Name = "critChance"
	local critDamageBonus = Instance.new("NumberValue", c)
	critDamageBonus.Name = "critDamageBonus"
	if critChance.Parent and critDamageBonus.Parent then
		print(c.Name.." Critical System Has Been Loaded")
	end
end

local function onPlayerAdded(player)
	print("P Added")
	if player.CharacterAppearanceLoaded then
		local c = player.Character
		OnCharAppearance(c)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Thanks for reading

2 Likes

Maybe you can do this:

local targetHealth = script.Parent.Health
local RealDMG = 1000
local BonusDMG = 3
local finalDMG = 0

local function DMG()
if math.random(5, 100) <= 5 then
finalDMG = RealDMG * BonusDMG
else
finalDMG = RealDMG
end

 targetHealth.Value -= finalDMG

end

Event:Connect(DMG)

1 Like

tysm for responding also i tried that code but is there a way to put it in a module script?

1 Like

No problem! and Yup, thats possible!

I usually do this:

– Module Script –

local FinalDMG = 0

local function takeDMG(RealDMG, BonusDMG, CriticalChance)
if math.random(1, 100) <= CriticalChance then
FinalDMG = RealDMG * BonusDMG
else
FinalDMG = RealDMG
end

return FinalDMG
end

return takeDMG

1 Like

… and in case you got something problem with your code. Make sure this what it looks like:
image

cuz this one doesnt shoe any sign of error in the line but it can cause a problem


:slight_smile:

1 Like

tysm for helping me, i very appreciate your help!

1 Like

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