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

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

Asked by 2 years ago

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)

0
Put your code into a code block MarkedTomato 810 — 2y

1 answer

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

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

0
I don't think you need the method wait for child since this is a server script. MarkedTomato 810 — 2y
0
No, but it will still work. I only changed line 9 Mathilinium 112 — 2y
Ad

Answer this question