A noob asking a noob question

How can i go about creating a script for a weapon so that everytime it is dropped by an NPC or looted from a chest it has a random damage output?

For example if a NPC drops a pistol 2 times how can i create a system in which each pistol will have it’s own unique damage output? Maybe from a 100-500 or 100-1000.

2 players can have the same weapon but one might be stronger than the other is what i need. I could possibly use math.random() but i don’t really understand how to implement that into what im looking for.

local damageRanges = {{100, 500}, {200, 500}}

local randomRange = math.random(1, #damageRanges)
local range = damageRanges[randomRange]
local minDamage = range[1]
local maxDamage = range[2]
local randomDamage = math.random(minDamage, maxDamage)

Basically just have an array of different damages ranges and choose randomly from the array each time the script is executed (once per tool creation).

So you’d have the source (original) tool stored somewhere like ReplicatedStorage, and then you’d clone the tool and the cloned tool will pick a random damage range.

So basically every tool i have in the game i should also have in replicated storage? And also does this script go inside the tool? I appreciate your help btw. This has been bugging me for a while now.

No, just the original tool stays in RS, then when it’s cloned that code executes and a random damage range is chosen for the cloned tool.

You won’t need to create multiple tools/scripts you can simply clone an instance by calling :Clone() on it. When cloning an instance all of its descendants are automatically cloned with it as well.

Ok that’s great to know because the way i was doing it before was awful practice. I had no idea it was this simple. Just one more question if you don’t mind. Where do i put the script you wrote above? In the tool itself?

I wouldn’t copy and paste that script expecting it to work off the bat, it was just an example but yes normally tool scripts are placed inside the tool itself.

Ah ok. I will use that as a starting point and see what i can come up with.