Hello! I am working on a game that includes this model (once clicked makes two parts rotate on the Y axis) and an object placement script. The object placement script is the one made by tunicus at this link.
Here's an example of the "acting up" that I'm talking about.
Also, if it helps at all, the cranks that work perfectly fine are rotated to 0 on the Y axis. And the ones that are acting up are rotated to either 90 or -90 on the Y axis.
Here's the script as of now.
wait()
local tycoon = _G.findFirstParent(script, "Tycoon")
local post = script.Parent.Post
local handle = script.Parent.Handle
local crank = script.Parent.Crank
local cd = script.Parent.ClickDetector
local postPos = post.Position
local handlePos = handle.Position
local crankPos = crank.Position
local handleOff = Vector3.new(handlePos.X - postPos.X, handlePos.Y - postPos.Y, handlePos.Z - postPos.Z)
local crankOff = Vector3.new(crankPos.X - postPos.X, crankPos.Y - postPos.Y, crankPos.Z - postPos.Z)
local startingCrank = crank.Rotation.Y
local TIME = 1 -- seconds
local POWER = 1
local FRAMES = TIME * 30
local TURN = 360 / FRAMES
local CRANK_COLOR = crank.Color
local timeForCombo = 0
local combo = 1
local isTurning = false
function turn ()
if not isTurning then
if timeForCombo > 0 then
combo = combo * 1.1
end
TIME = 1 / combo
FRAMES = TIME * 30
if FRAMES < 15 then
FRAMES = 15
crank.Color = Color3.fromRGB(255, 0, 0)
end
TURN = 360 / FRAMES
isTurning = true
for i = 1, FRAMES do
crank.CFrame = CFrame.new(postPos) * CFrame.Angles(0, math.rad(i*TURN), 0) * CFrame.new(crankOff.X, crankOff.Y, crankOff.Z)
handle.CFrame = CFrame.new(postPos) * CFrame.Angles(0, math.rad(i*TURN), 0) * CFrame.new(handleOff.X, handleOff.Y, handleOff.Z)
handle.Rotation = Vector3.new(handle.Rotation.X, handle.Rotation.Y, 90)
wait()
end
local i = 0
crank.CFrame = CFrame.new(postPos) * CFrame.Angles(0, math.rad(i*TURN), 0) * CFrame.new(crankOff.X, crankOff.Y, crankOff.Z)
handle.CFrame = CFrame.new(postPos) * CFrame.Angles(0, math.rad(i*TURN), 0) * CFrame.new(handleOff.X, handleOff.Y, handleOff.Z)
handle.Rotation = Vector3.new(handle.Rotation.X, handle.Rotation.Y, 90)
--tycoon.Power.GeneratePower:Fire(1)
timeForCombo = 1
isTurning = false
end
end
cd.MouseClick:connect(function ()
turn()
end)
while wait(0.1) do
timeForCombo = timeForCombo - 0.1
if timeForCombo < 0 then
timeForCombo = 0
combo = 1
crank.Color = CRANK_COLOR
end
end

1 comment
_G is hell