Viewportframe rotation not working (egg)

Hey,

I’m trying to make a egg collecting system like Egg Hunt 2022, except my egg doesn’t rotate and it’s pretty annoying. I can’t seem to get it fixed.

Pick up code:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local Debounce = false
local Model = script.Parent

script.Parent.Touched:Connect(function(Object)
	if Object.Parent:FindFirstChild("Humanoid") and Debounce == false then
		Debounce = true
		local Player = Players:GetPlayerFromCharacter(Object.Parent)
		if not Player.Eggs.LavaEgg.Value then 
			RemoteEvents.Handler:FireClient(Player, "NewEgg", Model)
			Player.Eggs.LavaEgg.Value = true
		elseif Player.Eggs.LavaEgg.Value then
			RemoteEvents.Handler:FireClient(Player, "AlreadyEgg", Model)
		end
		--task.wait(0.001)
		--Debounce = false
	end
end)

Client code:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local RemoteEvents = ReplicatedStorage.RemoteEvents

local EggFrame = script.Parent.EggFrame
local ViewportFrame = EggFrame.ViewportFrame
local EggLabel = EggFrame.EggLabel

local TweenInformation = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local Tween
local outcodeEgg 

--[[local function SetEgg(Egg)
	local ClonedEgg = ReplicatedStorage.Eggs[Egg.Name]:Clone()
	ViewportFrame:ClearAllChildren()
	ClonedEgg.Parent = ViewportFrame
	EggLabel.Text = Egg.Name.." Egg"
	outcodeEgg = Egg
	
	local Camera = Instance.new("Camera")
	Camera.Parent = ViewportFrame
	ViewportFrame.CurrentCamera = Camera
	Camera.CFrame = Egg.CFrame * CFrame.new(0, 0, Egg.Size.z * 1.5)
	
	Tween = TweenService:Create(Egg, TweenInformation, {Orientation = Vector3.new(0, 360, 0)})
end--]]

RemoteEvents.Handler.OnClientEvent:Connect(function(Argument, Egg)
	if not Argument then return end
	if Argument == "NewEgg" then
		Egg:Destroy()
		--SetEgg(Egg)
		EggFrame.Visible = true
		local ClonedEgg = ReplicatedStorage.Eggs[Egg.Name]:Clone()
		ViewportFrame:ClearAllChildren()
		ClonedEgg.Parent = ViewportFrame
		EggLabel.Text = Egg.Name.." Egg"
		outcodeEgg = Egg

		local Camera = Instance.new("Camera")
		Camera.Parent = ViewportFrame
		ViewportFrame.CurrentCamera = Camera
		Camera.CFrame = Egg.CFrame * CFrame.new(0, 0, Egg.Size.z * 1.5)

		Tween = TweenService:Create(Egg, TweenInformation, {Orientation = Vector3.new(0, 360, 0)})
	elseif Argument == "AlreadyEgg" then
		Egg:Destroy()
	end
end)

while true do
	if outcodeEgg then
		Tween:Play()
		Tween.Completed:Wait()
	end
	task.wait()
end
2 Likes

I have a feeling the issue is somewhere in the tween or the cframing, I’m unsure.

If your egg is setup in a straight up position, adjusting the Y value of this won’t make a difference. Either use X or Z depending on where the Top face of the egg is.

Also you don’t call a tween to make full circle. Once the orientation reaches 360, it won’t do a full loop back, it’ll sit there unless brought down again from 360. I would make another TweenService call to set it back to the original orientation it was at. I did this for my game and got a pretty good spinning object.

I don’t work with stuff like this often, so not sure if I helped too much.

Edit 1

Also yeah I just realized you make a clone of ClonedEgg and parent that to the Viewport Frame, but then you rotate the Y coordinate of “Egg” which is not the ClonedEgg that you declared. Maybe that’s the issue?

1 Like