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 3 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 — 3y

1 answer

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

Try changing your script to this:

1local Clicker = script.Parent
2local Object = game.ServerStorage:WaitForChild("smallship")
3local ObjectSpawn = game.Workspace:WaitForChild("Regen")
4 
5script.Parent.ClickDetector.MouseClick:Connect(function()
6   local CloneObject = Object:Clone()
7   CloneObject.Parent = game.Workspace
8   CloneObject.Position = Vector3.new(161, 2.5, -91)
9end)

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 — 3y
0
No, but it will still work. I only changed line 9 Mathilinium 112 — 3y
Ad

Answer this question