Hello there! So my friend and I are making a game! We have a lobby where coins should spawn and players should collect them, but instead of adding
while true do
…
script.Parent.Disabled = true
and repeating the same process a player can just stand in one place and farm coins easily which I don’t really want to be possible… So I am asking is there a way to make this possible? I didn’t try anything much right now cause I have no idea how to make that possible?
Create “coin regions.” Designate a single y height (yHeight) that they will appear on within this region.
Add a variable called yHeight within each region.
It would look like this :
local regions = {}; --Somehow, insert every coin into here. These will be randomly picked.
--Make each region have a variable that defines the Y Spot
while true do
local chance = math.random(1,10000); --Example chance, probably should be changed
if chance >= 9995 then --.05% chance per .03 seconds
local randomRegion = regions[math.random(1, #regions)];
local xvar = randomRegion.Position.X;
local zvar = randomRegion.Position.Z;
local yHeight = randomRegion.ySpot.Value;
--formula for random position within a region, excludes Y value
local randomSpot = Vector3.new(math.random(-xvar/2, xvar/2), yHeight, math.random(-zvar/2, zvar/2));
--From here, do whatever you need to create the coin
end;
wait();
end;
If you want, you could also input magnitude logic to prevent the coins from spawning inside of eachother.