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

I want my Wepon (a Stick) to do RANDOM Damage but its not..Why!?

Asked by
Tizzel40 243 Moderation Voter
5 years ago
Edited 5 years ago

here is my script for my Stick Wepon

on line 5, isn't it a table of numbers?

on line 18 I thought it would pick a random damage nuber between in the values but its not...

What is wrong

local fired = script.Parent.Remotes.damage  
local candmg = script.Parent.CanDamage


local damage = {7,5,6}



-------
fired.OnServerEvent:Connect(function(player)
    candmg = true
end)
script.Parent.Handle.Touched:Connect(function(hit)
    if candmg == true then
        candmg = false
        local ehum = hit and hit.Parent:FindFirstChild("Humanoid")
        if ehum then
            ehum:TakeDamage(damage[math.random()])
            print("You Dealed " .. damage.." Damage")

        else
            print("the Humanoid you ARE looking for is NIL")
            candmg = false
        end
    end
end)


--Scripted by Tizzel40

now it look like this but now it wont print that random damage number!

on line 19

local fired = script.Parent.Remotes.damage  
local candmg = script.Parent.CanDamage


local damage = math.random(5,7,8)



-------
fired.OnServerEvent:Connect(function(player)
    candmg = true
end)
script.Parent.Handle.Touched:Connect(function(hit)
    if candmg == true then
        candmg = false
        local ehum = hit and hit.Parent:FindFirstChild("Humanoid")
        if ehum then
            ehum:TakeDamage(damage)
            print("You Dealed " .. damage .." Damage")

        else
            print("the Humanoid you ARE looking for is NIL")
            candmg = false
        end
    end
end)


--Scripted by Tizzel40
0
local damage = math.random(5,7) greatneil80 2647 — 5y
0
omlllllllll thats cause ur setting it to that certain number, put damage after line 14 greatneil80 2647 — 5y

2 answers

Log in to vote
0
Answered by
Oficcer_F 207 Moderation Voter
5 years ago

I would recommend using a math.random()

Feks.

damage = math.random(7)

--later... 

ehum:TakeDamage(damage)

Something like that.

0
but no its not printing that random damage number.. Tizzel40 243 — 5y
0
Any errors? mixgingengerina10 223 — 5y
0
i fixed it myself Tizzel40 243 — 5y
0
Great! :) Oficcer_F 207 — 5y
Ad
Log in to vote
0
Answered by
RAYAN1565 691 Moderation Voter
5 years ago
Edited 5 years ago

You're doing the table wrong and using the math.random() incorrectly.

A table is identified by the computer as "{ }" instead of "( )". The math.random(minimum, maximum) can only contain two parameters. The minimum and maximum values restrict the function from choosing a random value from outside the boundaries.

Here's a way of doing what you want:

local damage = {5, 6, 7}  --this is a table

print(damage[math.random(1, 3)]) --chooses one of the following: damage[1] = 5; damage[2] = 6; damage[3] = 7

In the output, the above script will print a random value from 'damage' table.

Answer this question