My objects won’t follow the mouse when I make a placement system. Before, when experimenting with one object, it worked fine, now it seems that the objects just get cloned and stay in the same position. I used a text box, so the user can type in the object’s name. I have already checked the names, as well as printed out statements, and everything is correct.
There is an error:
Players.Awesomemode14.PlayerGui.PlacementScript:34: attempt to call a nil value
Here is part of of my code:
textbox.FocusLost:Connect(function(enterPressed)
if (enterPressed) then
if (objectFolder:FindFirstChild(textbox.Text)) then
local obj = objectFolder:FindFirstChild(textbox.Text)
local newObj = obj:Clone()
newObj.Parent = game.Workspace
part = newObj
startPlace = true
end
end
end)
while true do
wait()
if startPlace == true then
CalculatePosition(part) --here is the error (line 34)
end
end
function CalculatePosition(model)
CheckCollisions(model)
local x = math.floor(mouse.Hit.X / grid + 0.5) * grid
--local y = math.floor(mouse.Hit.Y / grid + 0.5) * grid
local y = 4
if y <= 4 then
y = 4
end
local z = math.floor(mouse.Hit.Z / grid + 0.5) * grid
model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame:Lerp(CFrame.new(x,y,z) * CFrame.Angles(0, math.rad(rotation * rotationDegree),
0), speed))
end
Ask if you need more info.
Thanks for the help!