Execute script when moved into a part

Hi, so I want to move a proyectile script into a part, so it has a force and becomes a proyectile, I have the script in a table, but I’ve tried to move it with table.remove and parent the part to it. But i don’t know how to execute the script exactly when its inside the part. So I need some help.

1 Like

Try something like this, if i understand right you need to move a script into a part and then execute it (try also table.move with remove)
If the script you have needs to start from the beginning try disabling it, move to the part you need and the reabilite again, hope this can help

Ill try it, as soon as I get something I’ll reply. Ty!

Also a tip, if you don’t need the script to execute when you start the game just keep it disabled and enable it when is in the part you need or just clone it and enable the copy, i use this for some minigames to take a map in the working area and use the same map with script enabled in the playable area

Thanks a lot! Just one more question, I’ve been having this question since i started learning to script, when I try to disable or enable a script that I’ve indexed with game.Something.Script, it won’t actually enable or disable it. And I still don’t know why. Sorry if it is a very basic question D:.

Sometimes i don’t know this either, i just use something like Script.Parent or similiar but yeah, this happens to me too

Yeah, I use parts in the workspace as triggers, so if I change the trigger’s transparency, the script will wait for it, with repeat wait() until trigger.Transparency == 1, and it will work, but I want to know why indexing it with game. , wont work. :*(

I also tried with Instance.AncestryChanged:Connect(function( script ), so when the script gets moved into the part, it will change it’s parent, and AncestryChanged should connect to my function, but it didn’t work as well.

I know is dumb to ask but have you tried with another script to do

    While true do
    If scriptBullet.Parent == workspace.things.thing then
 ScripBullet.disabled = false
    Wait(1)
    end

Or better

Repeat
Wait(1)
Until scriptBullet.Parent == workspace.things.thing

ScriptBullet.disabled = false

Oh, nono, i haven’t tried that, let me try it, i think it will work, :smiley:

Add a script to said part that will wait for a signal from “ChildAdded”, then fire a bindableevent after you check if it is the correct child, and add an endpoint to said script, you can delete the bindable and listener script at the end to save on memory

1 Like

Thanks, I´ll try that as well. Sorry if I ask too much, i’m kind of a beginner, are bindable events server sided?

They are on the same side as they are fired. Example: if you fire it on the server it sends it around the server, if you fire it on the client it fires it around the client.
Edit:
Remember to disconnect the connection to the ancestry changed event (deleting its script doesn’t disconnect it like bindable events)

What do you mean disconnecting it??

Deleting it will disconnect it

1 Like

You can also use the same script with the BulletScript and so on and use

Repeat
Wait(1)
Print("waiting...") --just for check
Until script.parent == Workspace.Things.Thing

And then run your code

If it is a remote event, or any RBXScriptSignal you can do:

RBXScriptSignal:disconnect(); -- This will stop the event from listening, therefore freeing up some memory
// A method of class (or Namespace) RBXSCRIPTSIGNAL;
// Summary: 
// Disconnects the event to free up memory; better to be used when the connection is not needed.
void disconnect(); 

There isn’t any documentation for disconnect, only a developer.roblox.com tutorial
RBXScriptSignal

1 Like

That didn’t work as well, it will repeat the wait, but wont listen to the parent change.

Another question. if I’m not mistaken, to fire a bindable event I have to:

In one script:

local bindable = game.Workspace.BindableEvent
bindable:Fire()

And in listener script:

local bindable = game.Workspace.BindableEvent
bindable.Event:Connect(function()
– script –
end)

Is that correct?

Yes, that is correct, remember; when you’re not using it anymore, destroy it

1 Like