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

Am making a placement system but cant get it to work just gives me error?

So, that you saw in the title i am making a placement system and i just gives me this error.

01:06:08.662 - Players.ObStactionD3stroy3r.PlayerScripts.LocalScript:23: attempt to index field 'PrimaryPart' (a nil value)
01:06:08.662 - Stack Begin
01:06:08.662 - Script 'Players.ObStactionD3stroy3r.PlayerScripts.LocalScript', Line 23 - local MakeCopy
01:06:08.662 - Script 'Players.ObStactionD3stroy3r.PlayerScripts.LocalScript', Line 50

Heres the script.

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")

local rep = game:GetService("ReplicatedStorage")
local materials = rep:WaitForChild("Materials")

local currentBlock = "WoodenBlock"
local currentcopy

local currentPiece = Instance.new("Folder")
currentPiece.Name = "currentPiece"

local function idk(num)
	return math.floor(num+0.5)
end

local function MakeCopy()
	local find = materials:FindFirstChild(currentBlock)
	
	if (find) then
		local c = find:clone()
		c.PrimaryPart.Transparancy = 0.5
		c.PrimaryPart.CanCollide = false
		c.Parent = game.Workspace
		currentcopy = c
	end
end

local function Move()
	local t, b = game.Workspace.CurrentCamera:WorldToViewportPoint(mouse.Hit.p)
	local find = materials:FindFirstChild(currentBlock)
	local tar = game.Workspace:FindPartOnRay(Ray.new(game.Workspace.CurrentCamera.CFrame.p, (mouse.Hit.p - game.Workspace.CurrentCamera.CFrame.p).unit * 500), currentcopy)
	
	if (b and find and currentcopy) then
		local tar = game.Workspace:FindPartOnRay(Ray.new(game.Workspace.CurrentCamera.CFrame.p, (mouse.Hit.p - game.Workspace.CurrentCamera.CFrame.p).unit * 500), currentcopy)
		currentcopy:SetPrimaryPartCFrame(CFrame.new(idk(mouse.Hit.p.X), mouse.Hit.p.Y+2, idk(mouse.Hit.p.Z)))
	end
end

local function Click()
	local t, b = game.Workspace.CurrentCamera:WorldToViewportPoint(mouse.Hit.p)
	local find = materials:FindFirstChild(currentBlock)
	
	if (b and find) then
		local c = find:clone()
		c.Parent = game.Workspace
		c:SetPrimaryPartCFrame(CFrame.new(idk(mouse.Hit.p.X), mouse.Hit.p.Y+2, idk(mouse.Hit.p.Z)))
	end
end

MakeCopy()

uis.InputBegan:connect(function(input)
	if (input.UserInputType == Enum.UserInputType.MouseButton1) then
		Click()
	end
end)

uis.InputBegan:connect(function(input)
	if (input.UserInputType == Enum.UserInputType.MouseButton1) then
		Move()
	end
end)

1 comment

0

Is WoodenBlock a Model? If so, does it have a Primary Part?

1 answer

✓ Accepted answer

This error means the object your moving has no PrimaryPart set. you can do this in the properties window

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