INTENTION: i have non-collided parts with a script to spawn a random item inside of them when a previously spawned item is moved out of range or gets destroyed
PROBLEM: i will have a very large amount of these item spawnpoints and i want to change the script from using a while loop to a function that detects when the item is moved at all (something like handle.GetPropertyChangedSignal("Position")), but when i put this function in the code, it was getting the object a bit too early (getting a nil value) so the function wouldnt work
QUESTION: how should i replace these lines of code and so it or the game doesnt shit itself
#item spawning code inefficiency
124 messages · Page 1 of 1 (latest)
Maybe put task.wait(itemRespawnTime) after spawnObject() instead? I'm not entirely sure on what I see here and what functions what
if i were to do that then the item would spawn immediately upon destroying the last one
itemSpawn is a basepart with only child being the script
another script adds an item as a child to the basepart
Ah. What is the modulescript then?
just sets it to 15
Can you also show the code? Kinda hard to help if you don't show me the code
there is no issue in the modulescript and its related scripts
the issue is in this one
Okay but there could be a problem with the modulescript that it doesn't tell you
its just a number value
i already tested it
it works
i want to make the code look something more like this but it retrieves handle too early and freaks out
@devout cipher
Hello
may I know where are you defining the part variable
hi
as far as I see you're creating the part variable as a parameter for the position of the childadded function
however this will only work inside that function, thats the origin of the problem
I may be wrong tho
you are likely right
alright so
as I see
you're trying to achieve than when an item spawns on the itemspawn it re-assigns variable item to part and re-assigns the variable handle to the handle of the new part created
yes
what is part supposed to be
like
is the part the same parent of handle
if thats the case you can replace part with handle.parent and that will fix it
replace the underlined part text with handle.Parent.Parent
handle.Parent.Parent = game.ReplicatedStorage
when i click play, a random model from randomspawn gets added as a child to itemspawn
fyi
thats coming from another script, you should find it
where is the script located?
in the explorer
serverscriptservice
it does it once and then the spawner scripts are supposed to do all the rest
which script is located at serverscriptservice
this one
of the one we were talking about before
the one that we were talking about before is a child to the spawn location part
this one is in serverscriptservice
if I understood correctly in order to fix this just change part.Parent = workspace.ReplicatedItems to handle.Parent.Parent = workspace.ReplicatedItems
now let me see the other one
rq
thats the whole script?
its quite simple
and which is the problem with this one?
this one does
I already gave u a solution for this
try it out and tell me how it goes
oops i accidentally left that in
dw
so, the problem is that "handle" variable is nil, as you can see when you define it you set it to nil and only redo it when an item is added to the spawn location part, as if I understood correctly you are adding something to the spawn location part o nthe second script right?
is baba printing?
so it is executing before the handle gets actually redirected, try adding a task.wait() statement at the start of the script after creating the values
it refused
wdym
should i be getting the part in a completely different way
ye
i am quite stumped
define
the two prints at the beginning ?
i think i accidentally left a script on
hold
like
what is the objective of the handle.GetPropertyCHangedSignal("Position") function
okay so the base intention is to parent the item to some other place when it gets too far away from the spawn location, thus triggering the spawn of another item
the magnitude checks do that
and the handle is a tool right?
the handle is parented and is the primarypart of a model
theres a prompt that lets you pick it up, destroying the model and giving you a tool
but that is less important now
can I see workspace.ItemSpawns folder
alr I see
the script is directly parented to the ItemSpawns folder?
the first one
its parented to the spawn locations
so, I assume the problem is that the handle function is executed for the first time when the script is first started
at this moment the handle is nil because you set it to nil
you could make a script inside the handle to get the handle this way and not on a global script
so you secure it never is nil
my advice is to make the position comparison inside a script on every handle and not on a global script like you're doing rn
no because the script will be parented to the handle
then check if script.parent.parent.parent is a spawn location
if the parent is nil the script does not exist
place a script inside the handle and everytime the script changes its parent check if the parent is a spawn location and do the function if that happens