I was following a tutorial on grid placements and when i test it,
it doesnt seem to work, i check on the dev console and find theres an error on line 100
stating index nil with ‘Clone’
-
What is the issue?
with the error i couldnt continue, i searched the script and couldnt find a thing to fix -
What solutions have you tried so far?
i have look up on the devforum but its still confusing but i know what attempt with index nil means but idk where did i get wrong
Heres The Code
-- Settings
--Booleans
local interpolation = true
local moveByGrid = true
local buildPlacement = true
-- Ints
local rotStep = 90
local maxHeight = 90
-- Numbers/Floats
local lerpSpeed = 0.8
-- Other
local gridTexture = ""
local placement = {}
placement.__index = placement
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
-- Constructure Var
local GRID_SIZE
local ITEM_LOC
local ROT_KEY
local TERM_KEY
-- Activation Var
local object
local placedObject
local plot
local stackable
-- Calc Var
local posX
local posY
local posZ
-- calculatate inital y pos
local function calculateYpos()
end
local function snap(x)
return math.round(x/GRID_SIZE) * GRID_SIZE
end
--calculate the model pos on grid
local function calculateItemPos()
if moveByGrid then
posX = snap(mouse.Hit.X)
posY = 4
posZ = snap(mouse.Hit.Z)
else
posX = mouse.Hit.X
posY = mouse.Hit.Y
posZ = mouse.Hit.Z
end
end
--sets model pos on pivot
local function translateObj()
if placedObject and object.Parent == placedObject then
calculateItemPos()
object:PivotTo(CFrame.new(posX, posY, posZ))
end
end
local function approvePlacement()
return true
end
-- Constructor Function
function placement.new(g, obj, r, t)
local data = {}
local metaData = setmetatable(data, placement)
GRID_SIZE = g
ITEM_LOC = obj
ROT_KEY = r
TERM_KEY = t
data.grid = GRID_SIZE
data.itemLocation = ITEM_LOC
data.rotateKey = ROT_KEY
data.terminateKey = TERM_KEY
return data
end
-- Activate Placement Id = Name, pobjs = placeObjects, plt = plot, stk = stackable
function placement:activate(id, pobjs, plt, stk)
--assigning values
object = ITEM_LOC:FindFirstChild(id):Clone()
placedObject = pobjs
plot = plt
stackable = stk
--make sure placement can activate properly
if not approvePlacement() then
return "Placement Could not Activate"
end
-- filters mouse object on stackable var
if not stackable then
mouse.TargetFilter = placedObject
else
mouse.TargetFilter = object
end
object.Parent = placedObject
end
runService:BindToRenderStep("Input", Enum.RenderPriority.Input.Value, translateObj)
return placement
the error is exactly twice under function placement:activate(id, pobjs, plt, stk)
or under the –assigning values comment