Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

CFrame script not making wheel move?

Asked by 3 years ago

I'm not very good at CFrame but it's supposed to move you .01 studs every time you click, I think it gets stuck somewhere. the script is located in a click detector.

script.Parent.MouseClick:Connect(function()
    local wheel = script.Parent.Parent
    wheel.Anchored = false

    if game.Workspace.Union.Value == 88 then
        wheel.CFrame = wheel.CFrame + CFrame.new(0,.01,0)
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

I'll start off by saying CFrame is wack at first. When moving parts using CFrame, the parts move based on their own XYZ axis, not the global one. (The global axis is the default axis, the part's axis accounts for the rotation of the part).

In addition, to move a part, you need to multiply the CFrames.

 wheel.CFrame = wheel.CFrame  * CFrame.new(0,.01,0)

you can mess around with the CFrame numbers to refine how the wheel moves. If you need to rotate the wheel using CFrame, try this:

wheel.CFrame = wheel.CFrame  * CFrame.Angles(math.rad(deg),math.rad(deg),math.rad(deg))

you replace "deg" with the number of degrees you want rotated for that axis. "math.rad" is required because CFrame.Angles() defaults to radians.

For more info see this:https://developer.roblox.com/en-us/api-reference/datatype/CFrame

If you need more assistance, reach out to me @BlobMaster#8156 or message me on roblox. Pls only do this for questions related to this topic.

I hope you found this helpful. Till next time.

0
Thank you! funkymonkey305 2 — 3y
0
Short answer: Math.rad stands for math.radians, converts cframe.angle to radians. JesseSong 3916 — 3y
Ad

Answer this question