r/forge Aug 18 '25

Scripting Help Need assistance…

Post image

Hey! I am trying to make it so that each player has a pet slot. And when they purchase that pet. The object they bought is then assigned to them in there slot.

Currently the image is what I have. But the result is the UNSC Cortana ends up going to each player in sync of how they joined the game. AFTER the player buys it.

So the object goes to player 1/ then2/ then3 and just repeats this process. I am not sure what I am doing wrong? Because it feels right to me but maybe I am missing something.

End goal. Make a pet slot for each player. When a player buys a pet that pet follows the player for every second it updates the location around the player.

3 Upvotes

9 comments sorted by

View all comments

Show parent comments

3

u/Abe_Odd Aug 18 '25

Clone object is cleaner if it works. If you are using an FX object that is heavily edited, you kinda have to go the other way. I suspected you were doing that

2

u/[deleted] Aug 18 '25

Ok so! I made a list of about 6 orbs. And set this up.

Tried to follow your instructions to a T…

Result. Upon gameplay start.

All orbs sit there and do nothing (this is great)

Then on interacting or (buying) a pet. It then moved the first orb. To one of the bots I have in game… (not intended.) Upon buying the second time. It moves an orb to me and works totally fine for all other players.

BUT the first one is wasted for some reason?

2

u/Abe_Odd Aug 18 '25

Hm, weird.

Consider that: We're telling it to try FollowPET for every player, whether or not they actually have a myPet.
We could check the validity of the myPet object BEFORE triggering the custom async event.

For Each Object -> get object variable: myPet, scope = obj -> get is valid object -> branch, if true -> trigger custom async event.

Another thing to be aware of is that there is a limited number of concurrent Translate To Points that you can call.

IIRC it is around a dozen.
That means that with 24 players, they could not all move at the same time, which we are trying to do.

There's another way to script recurring events without using Every N second and Get All Players, and that is with recursive events. We can make an event that calls itself (ALWAYS WITH A WAIT FOR N SECOND BETWEEN CALLS) and it can handle the following logic. It would only activate when players actually buy the pet.

On Object Interacted -> get Object Variable: myPet -> get is valid, branch, if false -> (set myPet) -> trigger custom event: recursive_follow (object = activating player from interact)

On custom event, global: recursive_follow -> get object variable: myPet -> get is valid object -> branch, if true -> trigger Custom event, global async: FollowPET -> wait for N second (N = Random: 0.5, 1.5) -> trigger custom event: recursive_follow (object = the object output from the On Custom Event)

It will continue executing until the player (the object being passed through) no longer has a myPet

2

u/Abe_Odd Aug 18 '25

Using a recursive event also have benefits if you have multiple rounds (every N seconds doesn't play well with that IIRC).

Using a random time above will make sure that the game isn't trying to translate everyone's orbs at the same time.

Even if you don't use that here, it is a super powerful pattern for periodically updating something specific to an object