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:

01local rs = game.ReplicatedStorage
02 
03rs.SpawnPlane.OnServerEvent:Connect(function(plane)
04    local existingPlane = game.Workspace:FindFirstChild(plane.Name)
05    if existingPlane then
06        existingPlane:Destroy()
07    end
08 
09    local clonedPlane = plane:Clone()
10    clonedPlane.Parent = workspace
11 
12    print("Spawned: " .. plane.Name .. "!")
13end)

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:

01local rs = game.ReplicatedStorage
02 
03rs.SpawnPlane.OnServerEvent:Connect(function()
04    local plane --Put here plane variable because it's nil
05    local existingPlane = game.Workspace:FindFirstChild(plane.Name)
06    if existingPlane then
07        existingPlane:Destroy()
08    end
09 
10    local clonedPlane = plane:Clone()
11    clonedPlane.Parent = workspace
12 
13    print("Spawned: " .. plane.Name .. "!")
14end)

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).

01local button = script.Parent
02local plane = game.ReplicatedStorage.Planes:FindFirstChild(button.Name)
03 
04while wait() do
05    if plane then
06        game.ReplicatedStorage.Planes:FindFirstChild(button.Name)
07        break
08    elseif button.Name == "Template" then
09        break
10    else
11        warn('error finding plane')
12        return
13    end
14end
15 
View all 21 lines...

Answer this question