Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My damage script is supposed to have a chance of critical damage but its not working?

Background: There are 2 string values inside of this script. one is the regular damage and one is the critical damage value.

This script is supposed to make you deal damage regular damage, or critical but it's not working

script.Parent.Touched:Connect(function(hit)
	local DmgValues = script.Dmg.Value and script.DmgCritical.Value
	local char = hit.Parent
	local hum = char:FindFirstChild("Humanoid")
	local criticalpicked = math.random(1, #DmgValues)
	if criticalpicked == 1 then
	if hum and char.Name ~= script.Parent.Parent.Name then
		hum.Health = hum.Health - criticalpicked
		script.Disabled = true
		wait(0.5)
		script.Disabled = false
	end
	end
	end)

1 answer

✓ Accepted answer
local DmgValues = script.Dmg.Value and script.DmgCritical.Value

and doesn't work like that. and is for conditions, like "if this is true and that is true." You want to use an array.

local DmgValues = {script.Dmg.Value, script.DmgCritical.Value}

Also note that criticalpicked = math.random(1, #DmgValues) is just going to equal 1 or 2. To actually get the right amount of damage, you have to do DmgValues[criticalpicked]

This discussion is preserved as it was. New answers, comments, and votes are closed.