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

How would I make the rotation save as a variable?

I've tried everything I can think of, but I keep on getting this error: ReplicatedFirst.Placement:24: bad argument #1 to '?' (CFrame expected, got number)

Here's the parts of the script that do stuff with rotation:

local rotation = CFrame.Angles(0, 0, 0)

model:SetPrimaryPartCFrame(CFrame.new(roundAToB(hit.X,1),4,roundAToB(hit.Z,1)* rotation)) -- errors here

and

uis.InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.R then
		model:SetPrimaryPartCFrame(model.HitBox.CFrame * CFrame.Angles(0, math.rad(90), 0))
		rotation = CFrame.Angles(0, math.rad(90), 0)
	end
end)

FULL SCRIPT:

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
wait(0.01)
local modelname = script.Parent.Item.Value
local modeltype = script.Parent.ItemType.Value
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local model = game:GetService("ReplicatedStorage"):WaitForChild("Items"):FindFirstChild(modeltype):FindFirstChild(modelname):Clone()
local rserv = game:GetService("RunService")
model.Parent = workspace.CurrentCamera

local uis = game:GetService("UserInputService")
local rotation = CFrame.Angles(0, 0, 0)

mouse.TargetFilter = model
function roundAToB(a,b)
	return(math.floor((a/b)+0.5)*b)
end
local sb = Instance.new("SelectionBox", model.HitBox)
sb.Color3 = Color3.new(100/255, 177/255, 105/255)
sb.Adornee = model.HitBox
mouse.Move:connect(function()
	local hit = mouse.Hit.p
	model:SetPrimaryPartCFrame(CFrame.new(roundAToB(hit.X,1),4,roundAToB(hit.Z,1)* rotation))
	--model:MoveTo(Vector3.new(roundAToB(hit.X,1),3.5,roundAToB(hit.Z,1)))
	--model:SetPrimaryPartCFrame(CFrame.new(model.HitBox.Position.X, 4, model.HitBox.Position.Z))
	local hb = model.HitBox
	wait()
	local region3 = Region3.new(
		Vector3.new(
			hb.Position.X-2,
			hb.Position.Y-3.5,
			hb.Position.Z-2.5
			),
		Vector3.new(
			hb.Position.X+2,
			hb.Position.Y+3.5,
			hb.Position.Z+2.5
			)
	)
	local partsinRegion = workspace:FindPartsInRegion3(region3, model)
	
	if partsinRegion[1] == nil then
		model.HitBox.SelectionBox.Color3 = Color3.new(100/255, 177/255, 105/255)
	else
		model.HitBox.SelectionBox.Color3 = Color3.new(162/255, 59/255, 52/255)
	end
	
end)

uis.InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.R then
		model:SetPrimaryPartCFrame(model.HitBox.CFrame * CFrame.Angles(0, math.rad(90), 0))
		rotation = CFrame.Angles(0, math.rad(90), 0)
	end
end)

mouse.Button1Down:connect(function()
	if model.HitBox.SelectionBox.Color3 == Color3.new(100/255, 177/255, 105/255) then
		local new =model:clone()
		new.Parent =model.Parent
		new.HitBox:Destroy()
		model.HitBox.SelectionBox.Color3 = Color3.new(162/255, 59/255, 52/255)
		new.Name = "Placed"..model.Name
		new.Parent = workspace
	else
	end
end)

Localscript | game is not filteringenabled

1 answer

Figured it out, these are the fixed scripts:

local rotation = 0

model:SetPrimaryPartCFrame(CFrame.new(roundAToB(hit.X,1),4,roundAToB(hit.Z,1))*CFrame.Angles(0, math.rad(rotation), 0)) -- errors here

and

uis.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.R then
        model:SetPrimaryPartCFrame(model.HitBox.CFrame * CFrame.Angles(0, math.rad(90), 0))
        rotation = rotation + 90
    end
end)

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