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

How do I clone something from replicated storage to workspace? Please help

Asked by 3 years ago

I've tried this:

local rs = game.ReplicatedStorage

rs.SpawnPlane.OnServerEvent:Connect(function(plane)
    local existingPlane = game.Workspace:FindFirstChild(plane.Name)
    if existingPlane then
        existingPlane:Destroy()
    end

    local clonedPlane = plane:Clone()
    clonedPlane.Parent = workspace

    print("Spawned: " .. plane.Name .. "!")
end)

but it gives me this error:

10:20:01.263 ServerScriptService.SpawnPlane:10: attempt to index nil with 'Parent' - Server - SpawnPlane:10

please help im confused

0
First of all, Function1; Your variable [plane is nil] RektwayYTB 123 — 3y
0
No, its defined as the object in ReplicatedStorage; the function is called from a LocalScript in a text button(which spawns the plane); inside the localscript, plane is defined as the model in ReplicatedStorage, and then i send signal to the RemoteEvent called SpawnPlane; along with the arguements of (plane). NickyPlayz2011 82 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Hello fellow Human, I heard you need help, Firstly let me explain your errors.

First of all; Your Varaible from the function which is "plane" isn't assigned into anything, Which means it's nil

Second; You can't clone the function variable; plane but you may know

And third; The Output may either error, or Print "nil".

And use plane as a variable in line 4.

Here is your fixed script:

local rs = game.ReplicatedStorage

rs.SpawnPlane.OnServerEvent:Connect(function()
    local plane --Put here plane variable because it's nil
    local existingPlane = game.Workspace:FindFirstChild(plane.Name)
    if existingPlane then
        existingPlane:Destroy()
    end

    local clonedPlane = plane:Clone()
    clonedPlane.Parent = workspace

    print("Spawned: " .. plane.Name .. "!")
end)

To mention, Edit line 4 for the plane variable because I don't know exactly where you store it.

I hope this helped you :D

0
i store the planes in a folder called "Planes"; the plane is defined in a LocalScript that targets a RemoteEvent; thats why i put "rs.SpawnPlane.OnServerEvent:Connect(function(plane))". NickyPlayz2011 82 — 3y
0
wait wth; so i replaced the code inside the function with this: "print(plane.Name)" and its printing my UserName??? NickyPlayz2011 82 — 3y
0
this means that "plane" is defined as a player somehow...??? NickyPlayz2011 82 — 3y
0
Wot NickyPlayz2011 82 — 3y
View all comments (5 more)
0
Also i cant use your script because im trying to get multiple planes; there are multiple textbuttons that spawn a plane, using only one serverscript to clone them into workspace. NickyPlayz2011 82 — 3y
0
Thanks i found a way to get all of the planes and find the one that was sent from the button; your post is marked as solution! NickyPlayz2011 82 — 3y
0
Have a nice day, Sir! RektwayYTB 123 — 3y
0
month later, (i fixed this a month ago tho) and if you were wondering what the issue was, it was that i forgot that firing events pass the Player who fired the event as the first arguement. NickyPlayz2011 82 — 3y
0
month later, (i fixed this a month ago tho) and if you were wondering what the issue was, it was that i forgot that firing events pass the Player who fired the event as the first arguement. NickyPlayz2011 82 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

btw this is the code inside the LocalScript that is firing the RemoteEvent (SpawnPlane).

local button = script.Parent
local plane = game.ReplicatedStorage.Planes:FindFirstChild(button.Name)

while wait() do
    if plane then
        game.ReplicatedStorage.Planes:FindFirstChild(button.Name)
        break
    elseif button.Name == "Template" then
        break
    else
        warn('error finding plane')
        return
    end
end

button.MouseButton1Click:Connect(function()     
    button.Text = "Spawning plane..."
    wait(0.5)
    button.Text = button.Name
    game.ReplicatedStorage.SpawnPlane:FireServer(plane)
end)

Answer this question