I am writing the loot spawning aspect of many of my WIP games. I was thinking of being lazy, making a folder with some invisible, untouchable and anchored parts which will be used to set the position of the cloned and desired item.
Now my biggest fear is not having cheaters know the spawn locations as if you have half a brain cell you would be able to memorise the spawns and the item is even highlighted for you if you’re close enough to the collectable item.
The goal is to really just reduce and refine the logic for the handling of this. I could use collection service and utilise tags however that would still require me to depend on not only another for loop to loop all instances but then I would have to get the CFrame and other information.
I also feel this could potentially be expensive in the future too as I plan to have some larger maps.
Instead I was thinking of doing something like this:
-- list of CFrame we will use to
local spawns = {
Vector3.new(0,0,0) -- example
}
-- spawn 5 collectable items at x spawns
for i = amountToSpawn, 0, -1 do
--spawning here
end
If you just set specific vector3 in your spawns array, regular players can try to remember it to cheese it.
If you really want to spawn at random locations, there is math.random()
Other than that, if you still plan to make spawns static (as in you set the vectors yourself) then make sure the script is somewhere the exploiters cant access it (serverstorage,serverscriptsservice)
This runs on the server. I did change the title to help better fit the goal however forgot to mention that this runs only and only ever on the server. The module is sat inside of ServerStorage so do not worry.
Why’s that? I did say that players could remember the spawns which is fine. I do the exact same thing in WWZ.
I already do this somewhat.
for i = 5, 0, -1 do
local chosen = spawns:GetChildren()[math.random(1, #spawns:GetChildren())]
if not ChosenSpawns[chosen] then
ChosenSpawns[chosen] = LootPool[math.random(1, #LootPool)]
end
end
That’s a goal but I am also looking for other peoples input on deciding the course of action to take when handling loot spawning. For now I assume my system is functionally fine.
Well, i cant really help you optimize if i dont know what im looking at (you only have a tiny bit of your code, that is fine because you want to protect your code but with the lack of context its hard to understand)
Let me ask a few questions before i try to help you as much as i can:
How do you want loot spawning to go? Do you want to spawn a random item at a spawn point? Or do you want to spawn a random item at a random spawn point?
When you mean course of action, what do you mean? Can you Expand on that please?
I am not bothered about changing functionality if it provides a better, more efficient or just overall a better system to do or put in place.
So the way this works is:
Get 5 spawn points for items
Generate the loot spawned by those points by assigning the item name to the spawn instance which is what this line does:
local chosen = spawns:GetChildren()[math.random(1, #spawns:GetChildren())]
if not ChosenSpawns[chosen] then
ChosenSpawns[chosen] = LootPool[math.random(1, #LootPool)]
end
From there handle spawning the item from the information given to ChosenSpawns which is used for spawning items onto the selected points.
For a little context the LootPool is just a string array. I am going to change this later on anyway.
local LootPool = {
"Ammo",
"Grenade",
"Resources",
"Breach",
"Special_Weapon"
}