How to call a specific function in specific model's script

I can’t seem to find the solution to this simple usage:

I am trying PartCache
https://devforum.roblox.com/t/partcache-for-all-your-quick-part-creation-needs/246641/2
to store FireBalls and use them when needed.

The original FireBall is in the ServerStorage and it has a script making it explode when touched and also after a delay, after it has been shot.

When getting a FireBall from the cache I have to call the function in it’s script to make it work every time the specific FireBall is reused.
How do I do this?

BindableEvent is not good right? As that would Fire the event in all of the FireBalls not just the one being reused. Or can that be targeted to a specific object?
I did not find that part in the documentation.

How is this done? It seems so common usage.

Please help!

2 Likes

Could you provide a script? Are you handling all of the fireballs from a single script, or does each fireball have its own script?

Each Fireball has their own script. It is the same thing for all of them, like: wait for a touch event and explode if it is a player, otherwise explode 5 sec after being “used” and spawn an explosion effect.

This all worked perfectly while the 1 Fireball was stored in ServerStorage and I simply cloned it and also it’s script would destroy itself once it has finished it’s “job”.

My problem now comes form the improvement of having them be in a PartCache and take them from there and put them back to the cache after they have finished their “job”.

In this case the script of the FireBall can’t run initially, but I have to send an event somehow to the specific fireball’s script to call the function in it to make it work AGAIN when it is used again and again from the PartCache.

I hope the issue is understandable. Am I explaining it properly?
I could share the scripts, but I don’t think that would help more, as the part I am asking how to do is not there.

1 Like

Why not just clone it from ServerStorage when you want to place one, and then connect to another function in the same script, or even in the same function? I don’t understand why you’d need an event though. If it’s just adjusting the transparency or something, you could make a table saving the defaults maybe? It’s a bit hard to determine a solution when we don’t really know what the explosion actually is.

I guess I am not explaining my problem clearly here and the question I have.
I’ll try again:

  • I have X# of Fireballs waiting in the PartCache to be used.
  • Each FireBall has one script which will do a bunch of stuff, like the touch event, exploding and spawning particles, etc.
  • The problem is that these things in the Fireballs’ script have to be inside a function so they only execute, and can be called once the fireball is used from the PartCache.
  • Question: How do I call that function in the specific Fireball which has been selected from the PartCache, to be used next?

If I send a Remote Event then that would activate the script in all the Fireballs, even the ones still waiting in the PartCache, right?
Can the RemoteEvent be sent to just one specific object?

I think I am missing something fundamental coding thing here, as this sounds like a trivial thing to do.

1 Like

Oh, I think I get it.

I don’t think you have to use a remote event at all. Assuming your fireballs are in the ServerStorage, it should just normally execute. If your fireball is a single object, just do script.Parent.Touched etc…, and have the script as a child of the fireball. It won’t execute unless it’s in workspace. You shouldn’t have to use an event at all.

What you described is how it worked perfectly before:
1 fireball in ServerSorage, that is being cloned and and then destroyed every time a fireball is needed.

The problem I have now is because I am trying to make it work with PartCache
https://devforum.roblox.com/t/partcache-for-all-your-quick-part-creation-needs/246641/2
With that the fireball(s) are not in ServerStorage but in ReplicatedStorage so they are ready to use faster, and not being cloned-destroyed all the time.

Hmm, but thinking about this and your reply I got an idea :bulb:
I could remove the fireball_script from the Fireball, move it to ServerScripts and clone that into the Fireball every time I use a Fireball from the PartCache.
Then the script would run and when the Fireball is done used, I would destroy the script from it as it is put back to the PartCache.

I’ll try that…

1 Like