Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I keep getting a Index Nil with Parent error with my boat cloning script how do I fix this?

I am making a pirate game but I have an error with my ship cloning script you have to press a button to spawn the ships but it does not work I have my ships located in Server storage and keep getting an error like this: Workspace.Regen.Spawn script:7: attempt to index nil with 'Parent' I have no idea why and it says this it also happens with every other script I try pls help:

local Clicker = script.Parent local Object = game.ServerStorage:WaitForChild("smallship") local ObjectSpawn = game.Workspace:WaitForChild("Regen")

script.Parent.ClickDetector.MouseClick:Connect(function() local CloneObject = Object:Clone() CloneObject.Parent = game.Workspace CloneObject.CFrame.position(161, 2.5, -91) end)

1 comment

0

Put your code into a code block

1 answer

✓ Accepted answer

Try changing your script to this:

local Clicker = script.Parent
local Object = game.ServerStorage:WaitForChild("smallship")
local ObjectSpawn = game.Workspace:WaitForChild("Regen")

script.Parent.ClickDetector.MouseClick:Connect(function()
   local CloneObject = Object:Clone()
   CloneObject.Parent = game.Workspace
   CloneObject.Position = Vector3.new(161, 2.5, -91)
end)

Also if you want to use CFram, you should read a little bit on this article: https://developer.roblox.com/en-us/articles/Understanding-CFrame

2 comments

0

I don't think you need the method wait for child since this is a server script.

0

No, but it will still work. I only changed line 9

This discussion is preserved as it was. New answers, comments, and votes are closed.