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

I have a clone script for my ship model when I click the button more than once I get an error why?

Asked by 2 years ago

I am making a pirate game and when I click the regen button to spawn another ship more than once I get an error like this:

The Parent property of SloopCopytwo is locked, current parent: NULL, new parent Workspace

So it does not work more than once and don't know how to fix this issue It also does not clone multiple of the same ship like I would like it too here is my script for the ship spawner.

game.ServerStorage.smallshiptwo.Archivable = true
copy = game.ServerStorage.smallshiptwo:clone()
game.ServerStorage.smallship.Archivable = false
local detector = game.Workspace.Regensloop
script.Parent.ClickDetector.MouseClick:Connect(function()

copy.Parent = game.Workspace

copy.Name = "SloopCopytwo"

    copy:MoveTo(Vector3.new(152, 2.5, -90))

end)

thanks.

0
Why is it not Archivable in the first place? And also the model may have been garbage-collected, since I see that the parent are set only if the ClickDetector is Triggered. NotThatFamouss 605 — 2y
0
@NotThatFamouss how do I fix that? Puffyjasonrocks84 39 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Okay, so. Just like what I said in the comment, it may have been garbage-collected, garbage-collection is an automatic process of freeing up space in a computer's memory by removing data that is no longer required or in use. And I advise to actually set the model's archivable to true.

Anyway, here's my solution: (Untested)

local ServerStorage = game:GetService("ServerStorage") -- This is just personal preference, you don't have to set a variable for this. You can just use game.ServerStorage

local detector = workspace.Regensloop -- Question, what's the use of this in your script?

script.Parent.ClickDetector.MouseClick:Connect(function()
    local Copy = ServerStorage:FindFirstChild("smallshiptwo"):Clone()
    Copy.Name = "SloopCopytwo"
    Copy.Parent = workspace

    Copy:MoveTo(Vector3.new(152, 2.5, -90))
end)

So, what changed is that I moved the cloning into the MouseClick function. If you do it outside of the function, it would only clone once, but in this script, it clones whenever the ClickDetector is triggered.

0
hmm wierd I got an error :Workspace.Regensloop.Script:7: attempt to index nil with 'Name' Puffyjasonrocks84 39 — 2y
0
Is the model Archivable? NotThatFamouss 605 — 2y
0
yeah, I set it to true sorry for the late response Puffyjasonrocks84 39 — 2y
0
Ah, sorry. on line 6, it's supposed to be smallshiptwo, not smallship. I didn't read your code properly. NotThatFamouss 605 — 2y
0
Thank you so much this really helped a lot and I added the local.detector part becuase if I did not I would get a nil error for some reason. Puffyjasonrocks84 39 — 2y
Ad

Answer this question