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

How can I move a Part By Studs?

Error: attempt to multiply a Vector3 with an incompatible value type or nil So I'm trying when you click the part, it should be like 500 studs, then after 5 seconds it should come back, and it's not working, any help?

local allGoldbars = workspace.GoldBars:GetChildren()

for i, v in pairs(allGoldbars) do
	local clickDetectorsGoldBars = Instance.new("ClickDetector")
	clickDetectorsGoldBars.Parent = v
	
	
	clickDetectorsGoldBars.MouseClick:Connect(function(player)
		print("hi")
	
	local francs = player.leaderstats.Francs
    francs.Value = francs.Value + 1

	v.CFrame = v.CFrame - Vector3.new(0, 500, 0) * CFrame.Angles(0, math.rad(90), math.rad(180))
    wait(5)
	v.CFrame = v.CFrame - Vector3.new(0, -500, 0) * CFrame.Angles(0, math.rad(90), math.rad(180))
	
	end)
end

2 comments

0

Could you post on which line that error is occuring?

0

v.CFrame = v.CFrame - Vector3.new(0, 500, 0) * CFrame.Angles(0, math.rad(90), math.rad(180))

2 answers

✓ Accepted answer

Mistake was the order of operations. The first calculation was "Vector3 * CFrame" which is not allowed.

v.CFrame = v.CFrame - Vector3.new(0, 500, 0) * CFrame.Angles(0, math.rad(90), math.rad(180))

You can fix it by adding parentheses around v.CFrame - Vector3.new(0, 500, 0) to make sure that part is calculated first. In which case you end up with "CFrame * CFrame".

I got help on discord:

v.CFrame = (v.CFrame - Vector3.new(0, 500, 0)) * CFrame.Angles(0, math.rad(90), math.rad(180))

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