So far, I've created a script inside an NPC or Zombie however you want.
And the point of Script is to give random materials every time when "Zombie" dies.
The script works, but when Zombie dies, it gives me** always** the same material...
So, I know that there's the problem with RandomNumber variable but I have no idea on how to make this to work...
The thing that I've had in my head was: *If a zombie dies that means that script will reset and it will be other numbers... * but obviously it didn't go by that way.
In the following script, I've added marks where the error occurs.
local RandomNumber = math.random(1,5) -- Error here
local Humanoid = script.Parent.Humanoid
function PwntX_X()
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Database = tag.Value:FindFirstChild("Database").Value_Inv
if Database ~= nil then
if RandomNumber == 1 then
Database.Rock_Value.Value = Database.Rock_Value.Value + 1
elseif RandomNumber == 2 then
Database.Stick_Value.Value = Database.Stick_Value.Value + 1
elseif RandomNumber == 3 then
Database.Plank_Value.Value = Database.Plank_Value.Value + 1
elseif RandomNumber == 4 then
Database.Plank_Value.Value = Database.Plank_Value.Value + 1
elseif RandomNumber == 5 then
Database.IronIngot_Value.Value = Database.IronIngot_Value.Value + 1 -- Always incerases this value.
end
wait(0.1)
script:Destroy()
end
end
end
end
Humanoid.Died:Connect(PwntX_X)

15 comments
math.randomseed(tick()) should throw out the first not-so random number, which is a known limitation of lua
put that at the top of the script
Okay, let me try that
Eh, so will it be like math.randomseed(tick(1, 5)) or
no, just put it at the top, and keep what you have with math.random()
So, like first line would be math.random thing and second line would be with randomseed tick without 1, 5
no, put math.randomseed() at the top, keep everything you have but move it down 1 line for what I have put.
Sec
Ok lemme see
Roblox Studio has stopped responding... -_-
Now it updates only second value...
You should try doing a while true do loop with math.random
It's a bad idea, it would never run the rest of the code
after the math.randomseed do for i = 1, 100 do math.random() end
incapaz your method doesn't work