Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does the RemoteEvent of a cloned part not fire?

Asked by 5 years ago

Hey! So I've been trying to make this inventory system, and I've encountered a weird problem.Basically when I'm next to a part I can press F, the script on the PlayerGUI fires the remote event of the brick, and the brick is destroyed. This works fine, however if the brick is cloned from ReplicatedStorage, the event doesn't fire.

For the pick up function I only have a for loop that iterates through the parts, and checks if I'm close enough to be able to pick the object up. The line of code that fires the event looks like this:

object.Event:FireServer()

Here is the code for the cloning:

                        local obj = v:Clone()
                        obj.Parent = game.Workspace.Objects
                        obj:MoveTo(rootPart.Position)

v is from a for loop where i iterate over the objects in replicatedstorage to find the one i want to copy.

and here is the script for the remote event:

script.Parent.Event.OnServerEvent:connect(function(Player)
    print("fired")
    local Mag = (script.Parent.Center.Position-Player.Character.HumanoidRootPart.Position).magnitude
    if Mag <= script.Parent.Range.Value then
        script.Parent:Destroy()
    end
end)

Everything works fine if the object is not cloned.

Why can I fire the event of objects that already were in the workspace but I cannot fire the event of cloned objects? What am I doing wrong?

Answer this question