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.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How can I move a Part By Studs?

Asked by
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

2 answers

Log in to vote
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".

Ad
Log in to vote
0
Answered by
EEnergy8 158
9 days ago
Edited 9 days ago

I got help on discord:

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

Answer this question