Sometimes it works?

So for right now, i am trying to make it so when the skeleton dies if the number that was chosen is greater then 10 then he drops a skull. It seems to work only sometimes any suggestions?

It may be because math.random is giving the same number each time, is there a way to solve this?

1 Like

There’s uh quite a bit of mistakes in this code. But don’t worry cause it’s part of the learning process.

First of all, you’re only generating the random number 1 time since it’s outside of the while true loop.

nvm the above is wrong since you only want it to generate once, sorry

Secondly, you don’t even need the while loop and the if script.Parent.Humanoid.Health part since you can just use

Humanoid.Died:Connect(function()
   -- blah blah blah
end)

Third of all (not really related to your code), but uh it would be easier if you could upload your code in markup here like:

print("Hi this is in markup!")
1 Like

Wait wait wait did this actually solve your problem? I don’t think it really did, can you maybe clarify a little more?

1 Like

I mean the main problem is now solved. Or both of the problems are. I just didn’t use the right event. The only problem with the solution is that when you put the math.random into the while true do, it sometimes will print 2 numbers because its constantly changing.

2 Likes

and also the items dont get cloned to the humanoid when the humanoid dies. The only item that dose get teleported is the “GoldSkull” When the value is = to 2

2 Likes

I tried using your advice

Is there any other errors?

1 Like

You don’t really need the while true do loop at the top nor do you need that wait(3) below it (also for future reference, task.wait is more precise than wait)

If there’s a lot of skeletons in your game, you could use Debris (game:GetService("Debris")) to destroy a lot of skeletons efficiently.

Debris:AddItem(item, delay)

There’s probably more I could add but that should be pretty good