hello i have a tower defense game and normally if you want to place a tower you press R key and it rotates it but i want to tween that rotation so it looks more good i am a beginner scripter i did try some code but it didnt work as planned it spinned out of control when i pressed R key
Code when i tried adding tween (i tried from my own mind) :
elseif input.KeyCode == Enum.KeyCode.R then
local rotationSpeed = 10
local rotationTweenInfo = TweenInfo.new(rotationSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
rotation += 90
if rotation == 90 or 180 or -90 or -180 then
local rotationTween = TweenService:Create(towerToSpawn.PrimaryPart, rotationTweenInfo, {Orientation = Vector3.new(0, rotation, 0)})
rotationTween:Play()
end
code when i did not add tween :
elseif input.KeyCode == Enum.KeyCode.R then
rotation += 90
In the targetcframe variable if i remove math.rad or keep math.rad either way it works but without rotating tween the rotation works as normal but just no tween while rotating
elseif input.KeyCode == Enum.KeyCode.R then
local rotationSpeed = 0.01
local rotationTweenInfo = TweenInfo.new(rotationSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
rotation += 90
if rotation == 90 or 180 or -90 or -180 then
local TargetCFrame = towerToSpawn.PrimaryPart.CFrame * CFrame.Angles(0, rotation, 0)
local rotationTween = TweenService:Create(towerToSpawn.PrimaryPart, rotationTweenInfo, {CFrame = TargetCFrame})
rotationTween:Play()
end
I also setup a few prints to debug this and it printed rotation tween has played maybe it might be the speed or something in tween info
Edit : even after setting rotation to 10 or 1 it’s the same ; the tower rotates without rotation tween