Execute script when moved into a part

When I fire the bindable event from a script in replicated first, the listener script in the workspace won’t trigger, why is that?? The script in replicated first is a localscript, and the listener script is a normal script, does this have to do with the problem?

They have to both be the same script class

1 Like

Yeah I thought so, I’ll try it now.

A possible work to this would be this:

function setParentAs()
    -- do initial code
    if (script.Parent == INSTANCETOMOVEFROM) then
        script.Parent = THEREFERERINSTANCE
        wait()
        setParentAs()
    else
        -- Do referer code
    end
end
1 Like

Yeah but the part generates mid game, also your right, I think child added is the best solution here, because replicated first won’t run scripts, only local ones, therefore I cannot fire the bindable from replicated first to workspace. So I’ll try using child added.

Should this work?

game.Workspace.GenkiBall.ChildAdded:Connect(function(child)

    if child == "GenkiBall" then
	    local genkiball = child -- save the part
	    local wantedscript = genkiball:WaitForChild("ThrowGenki") -- script I want to enable (proyectile script)
	    if wantedscript then 
		    script.Parent.Parent.GenkiBall.ThrowGenki.Disabled = false -- enable it.
	    end
    end

end)

You might want to look into using CollectionService (and tagging the parts):

So i would tag the part, and move the script into the tag??

Take a look at this:

So I tag my part, listen to it with GetInstanceAddedSignal, and execute the function that would move my script to the tagged part.

I don’t know what your projectile script does, but the point of using CollectionService is that you don’t have to do stuff like moving scripts into parts. For example, in the listener for the signal you’ll connect to,
the argument would be the Part that you tagged, so your listener could set whatever needs to be
set on that Part and do some other stuff if necessary.

Oh, I get it, that is way better than I thought, sorry if my understanding is this bad, i just started learning heh. I’ll try it !

Thank you, that solved it !!, thanks @DenisxdX3, @PseudoPerson, @0x6e7367 and @Club_Moo !!

1 Like