New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

# How can I move a Part By Studs?

EEnergy8 158
9 days ago
Edited 9 days ago

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


0
Could you post on which line that error is occuring? FloweryMonkeyboy5 984 — 9d
0
v.CFrame = v.CFrame - Vector3.new(0, 500, 0) * CFrame.Angles(0, math.rad(90), math.rad(180)) EEnergy8 158 — 9d

1
Answered by 9 days ago

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".

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