local tweenservice = game:GetService("TweenService")
local shakeAngle = math.rad(15) -- Angle to shake the egg
local shakeDuration = 0.1 -- Duration of each shake
local scaleIncrement = Vector3.new(0.1, 0.1, 0.1) -- Amount to increase the scale by
local verticalOffset = Vector3.new(0, 0.05, 0) -- Vertical offset to prevent the egg from getting stuck
local numShakes = 15 -- Number of shakes
-- Store the original position and orientation of the egg
local originalCFrame = egg.CFrame
local originalSize = egg.Size
-- Function to shake the egg
local function shakeEgg()
game.ReplicatedStorage.cracl:Play()
for i = 1, numShakes do
-- Shake to the right
local tweeninfo = TweenInfo.new(
shakeDuration,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
tweenservice:Create(egg, tweeninfo, {CFrame = originalCFrame * CFrame.Angles(0, 0, shakeAngle), Size = egg.Size + scaleIncrement, Position = egg.Position + verticalOffset}):Play()
wait(shakeDuration)
-- Shake to the left
local tweeninfo2 = TweenInfo.new(
shakeDuration,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
tweenservice:Create(egg, tweeninfo2, {CFrame = originalCFrame * CFrame.Angles(0, 0, -shakeAngle), Size = egg.Size + scaleIncrement, Position = egg.Position + verticalOffset}):Play()
wait(shakeDuration)
end
end
Why is the egg not getting stuck in the ground in studio but when i try it in game it gets stuck into the ground?
Its because I think studio servers are more optimized compared to real roblox servers. Maybe put the Y coordinate of the cframe a bit higher anyway. Also do tween on the client for more optimization so that if you do the real one in game its optimized.
you can try using math.floor or math.ceil to round specific values if needed.
or using print statements:
local function shakeEgg()
-- ... your existing code ...
-- Before shaking right
print("Egg CFrame before shaking right:", egg.CFrame)
-- Play shake right tween
tweenservice:Create(egg, tweeninfo, { ... }):Play()
wait(shakeDuration)
-- After shaking right
print("Egg CFrame after shaking right:", egg.CFrame)
-- ... repeat for shaking left ...
end
Well okay. I didn’t really read your code but judging from that sentence I’m assuming the part sorta flings? Then weaken the offset or whatever is happening. OR just optimize the tween for the actual servers by doing it on client-side for example.