#how can i make this knob turn the right way?
1 messages · Page 1 of 1 (latest)
code: local AXIS="x" -- "x","y","z"
local DIR=1 -- 1 or -1
local k=script.Parent
local p=k:FindFirstChild("Mesh1")
local d=p and p:FindFirstChild("ClickDetector")
local s=game.ReplicatedStorage:FindFirstChild("ClickSound1")
local l
local f=workspace:FindFirstChild("Lights")
if f then
for _,o in f:GetChildren() do
if o:IsA("Part") then
l=o:FindFirstChildOfClass("PointLight")
if l then break end
end
end
end
if not(p and d and s and l)then return end
local n=5
local v=1
local a=-90
local b=90
local t=(b-a)/(n-1)
local w=p:FindFirstChildOfClass("Weld")
local o=w and w.C0
local function r(x)
x=xDIR
if AXIS=="x"then return CFrame.Angles(-x,0,0)
elseif AXIS=="y"then return CFrame.Angles(0,-x,0)
else return CFrame.Angles(0,0,-x)end
end
local function u()
local e=math.rad(a+t(v-1))
if w and o then w.C0=o*r(e)
else p.CFrame=CFrame.new(p.Position)*r(e)end
l.Brightness=(v/n)*10
end
u()
d.MouseClick:Connect(function()
v=v+1
if v>n then v=1 end
u()
local m=s:Clone()
m.Parent=p
m:Play()
game.Debris:AddItem(m,2)
end)
** You are now Level 1! **
please dont just use letters as variable names 💔
Yes this is really easy to read ❤️🩹 ❤️🩹
its not my fault thats how assistant simplified it
I can barely read the code so I have no idea whats going on
Generally speaking you need to rotate the cframe before applying it to the part
So, for example, multiply it by CFrame.Angles(0, math.rad(90), 0)
If your reading the knob's cframe in order to rotate it more, you would have to undo the above transformation
A better solution would be to store the rotation seperate from the knob