Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago
Edited 7 years ago
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]

Ad

Answer this question