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
I would recommend using a math.random()
Feks.
damage = math.random(7) --later... ehum:TakeDamage(damage)
Something like that.
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.