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)
Hello asworme!
Have you tried to call it in the function PwntX_X ?
local Humanoid = script.Parent:WaitForChild("Humanoid") function PwntX_X() local RandomNumber = math.random(1,5) 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 end wait(0.1) end end end end Humanoid.Died:Connect(PwntX_X)