Concept!
Hi = 5
print(Hi)
Hi = 10
print(Hi)
Output:
5
10
As ROBLOX runs this script, two lines are printed. But why aren't they the same? Or why aren't they both in the same line? That's because variable Hi is defined in line 1, but then it's redefined (or replaced) with another value in line 4.
Same case with your onClick().
function onClick()
Open.CFrame=CFrame.fromEulerAnglesXYZ(0, 0.45, 0)
OpenStick.CFrame=CFrame.fromEulerAnglesXYZ(0, 0.45, 0)
end
function onClick()
Open.CFrame=CFrame.fromEulerAnglesXYZ(0, 0, 0)
OpenStick.CFrame=CFrame.fromEulerAnglesXYZ(0, 0, 0)
end
So, use different names. Or combine the two functions into one.
Since you're dealing with a switch/toggle type script (where it's just on and off), I'll give you a sample script to base your work off of.
local isOn = false
local function Switch()
if isOn then
print("Turning off...")
else
print("Turning on...")
end
isOn = not isOn
end
local isOn = false
local function TurnOn()
print("Turning on...")
end
local function TurnOff()
print("Turning off...")
end
local function Switch()
if isOn then
TurnOn()
else
TurnOff()
end
isOn = not isOn
end
CFrame!
When you're using CFrame.Angles() only, you're making a new CFrame. The default new CFrame is CFrame.new(0, 0, 0). What you want to do is define the CFrame relative to its current CFrame.
Part.CFrame = Part.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 0)
CFrame.fromEulerAnglesXYZ() (or CFrame.Angles() for short) accepts values in radians. Which is, like, trig stuff (math.pi /2 = 90 degrees; math.pi / 4 = 45 degrees), but there's a mathematical function that lets you convert these degree values into radians, if that's easier for you.
Part.CFrame = Part.CFrame * CFrame.Angles(0, math.rad(45), 0)
To go back to the original CFrame, you can negate the original angle value.
Part.CFrame = Part.CFrame * CFrame.Angles(0, math.rad(-45), 0)
Any questions? Comments? Skepticism? Comment down below or PM me!