local EggGUI = script.EggGUI
local Frame = EggGUI.Frame
local location = game.Workspace.Eggs.EggDispenser1.Egg_Model.OuterEgg
local Container = game.Workspace.Eggs.EggDispenser1.Egg_Model.Hitbox
local studs = 30 -- The studs from the player to part increase to make gui visible from long distance
local inRange = script.inRange
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local guiTween = tweenService:Create(Frame, tweenInfo, {Size = UDim2.new(1, 0, 0.9, 0)})
local function getDistance(part)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoidRoot = char:WaitForChild("HumanoidRootPart")
local distance = (part.Position - humanoidRoot.Position)
return distance.Magnitude
end
game["Run Service"].RenderStepped:Connect(function()
if getDistance(Container) <= studs then
print("Done1")
EggGUI.Enabled = true
EggGUI.Parent = location
guiTween:Play()
guiTween.Completed:Wait()
else
EggGUI.Enabled = false
EggGUI.Parent = script
print("Done2")
end
end)
I’ve been spending days trying to fix this code so now I’m using my last resort, the forum.
I’ve half solved the problem but let me explain what it should be doing.
First of all I’m aiming to make it so when the user is close enough to the egg it will open a Billboard GUI using a tween, in the process I also parent the Billboard GUI from the client side to the workspace so only the local player can see it.
The problem is when I go back into the required stud distance more than once it completely does not run the tween and instead just does everything else except the tweening. Basically:
1st Approach - Runs tween and GUI is visible.
Leaves the required stud distance and goes back in.
2nd Approach - Does not run tween but billboard GUI is visible.
Any help is appreciated, thanks.