so as of now, the script i have made gets a table of spawnpoint parts, gets a table of items it could spawn and then spawns them at the cframes of every existing spawnpoint, so far so good
what im wondering is, how would i go about spawning a random item when an item is taken away from a spawnpoint or destroyed (restocking the spawnpoint)?
i do not wish to have anyone code the entire thing for me, i just want to be guided in the right direction or be given code snippets or links that could be helpful
would i have to do something with touch events?
#improving random item spawning
1 messages · Page 1 of 1 (latest)
have your table of spawn locations track what item is at the location or each item track what spawn location it is at then you now know which spawn location had its item picked up so you can then know to respawn a new item there
ez
uuuuuhh
could you explain how to make the spawn locations track the items with a bit more detail
table
not exactly "more detail" but okay ill see what i can do
tables very versatile. practice them
could i do something like parenting the spawned items to the spawnpoints themselves and then having a script in the spawnpoints that waits for an ancestry changed event, then when it detects that theres no item anymore it gets the random item table and spawns a random item again after like 10 minutes
probably
would also need to add a failsafe if the player somehow managed to throw the item into irretrievable oblivion without destroying it
not quite sure how to approach this
death plane destroys parts at -500
but if its in the world and out of reach then yea haha it gone
idk, you sound like you got this
maybe
have at it and just try different stuff
what can i do with position.magnitude
lol
yea keep practicing. no one fully understands what they're doing when trying something for a first time
you just have to http://tryitands.ee
i track the child of the spawnlocation
when its position changes i check for position magnitude relative to spawnlocation
if its too high
i put child into foster parent
spawnlocation cry and make another child after enough time
would this be inefficient or ugly
efficiency and how it looks should be the dead last thing you should be concerned about right now when you don't even have a solid idea of how to make it work at all in the first place.
im asking theoretically
priorities bruh. get it working first, and then maybe consider if your solution is trash, as opposed to considering if your proposed solution which doesn't exist yet is efficient and flawless and then putting pen to paper and trying to get it working.
it's probably the biggest mistake a beginner can make.
im having the fun
as a beginner you're going to write trash code, you can't avoid it. embrace the jank spaghetti code, keep calm, and make games 👍
that's the spirit! ⭐ dont worry about perfection. just make stuff that works.
my foolish ass accidentally forgot to set the proper position of a raycast that detects the highest point my ghoulish abominations could spawn at so they started spawning in my basement and mauling me
but i fixed it already so
how amusing
there will be many such oversights in everything you create. you don't know enough to reach peak perfection and efficiency, so don't bother. make, playtest, iterate, do this enough and you'll eventually have seen so many problems that you know what to look for most of the time, but even when you hit my stage you can still be surprised by dumb things
hmm
like the fact that rbxscriptconnection's don't inherit from the Object class (which should give it an :IsA() function)
that's just stupid on roblox's part, the docs lie 😮💨
there are many systems in my game that track if its day or night
do i make it into a module script somehow
docs say every class should inherit from object, yet clearly that's not true, example right there. in what world of perfect efficiency would you have known the docs were wrong? you see, you cannot account for everything.
idk modulescript, lighting.timeofday just play with stuff.
there's always more than 1 way to skin a cat.
i should add cat eating into my game
and in programming, infinite ways to do pretty much anything.
players can already eat my not human humanoid monsters
okay ill see what i can do with what i just conspired
oh what the fuck
oops
nice
i attempted disemboweling my original spawning code
@versed wagon sir i am blind why did it spawn ten thousand of my items
did my descendant removing function run that many times
save me print
ah
its because of the children of the item
ill just make it detect one of the parts inside
apologies for the ping
i did it
You could maybe parent the items to the spawn parts and check when a child is removed from the parts, and if it’s one of the items you spawned then restock it. If the items are tools picked up by the player or are items that are destroyed then this should work
conspiring with childadded and childremoved
My phone is lagging and I just typed that out just for everything to load once it sent
mmm
i really dont wanna use any while loops to check the position of items
how do i make the getpropertychangedsignal function wait until the handle is defined
how should i do this differently
@versed wagon return for one last time smart fella i am foolish
** You are now Level 7! **
He is forever gone, as he knows you no longer truly need him
Write local handle = nil
Somewhere above and then change it in the script
Do you know what I mean?
yer
Try adding the getpropertychangedsignal in the child added thing
So one big function instead of 2
i did try that
but ill try it again
no reaction
-- Services --
local ServerStorage = game:GetService("ServerStorage")
-- Script --
local itemsFolder = ServerStorage.Items.RandomSpawn
local itemSpawn = script.Parent
local items = itemsFolder:GetChildren()
local item = nil
local handle = nil
local itemRespawnTime = itemSpawn:GetAttribute("ItemRespawnTime")
local debounce = false
local function spawnObject()
local clone = items[math.random(1, #items)]:Clone()
clone:SetPrimaryPartCFrame(itemSpawn.CFrame * CFrame.new(0, 0.5, 0) * CFrame.Angles(0, 0, 90))
clone.Parent = itemSpawn
end
itemSpawn.ChildAdded:Connect(function(part)
print("baba")
item = part
handle = part:FindFirstChild("Handle")
handle:GetPropertyChangedSignal("Position"):Connect(function()
print((itemSpawn.Position - handle.Position).Magnitude)
if (itemSpawn.Position - handle.Position).Magnitude > 10 then
handle.Parent.Parent = workspace.ReplicatedItems
end
end)
end)
itemSpawn.ChildRemoved:Connect(function()
task.wait(itemRespawnTime)
spawnObject()
end)
there are no errors
i think that function might only be active for that one singular moment that the childadded function is active
Try adding a wait() or a wait(0.2) after you define the handle, it might not be fully loaded