You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
A good tween that doesn’t constantly add!
What is the issue?
The issue is when i step on the part it constantly keeps adding 5 to the position when I only want it do it once!
What solutions have you tried so far?
Finding a solution!
local tweenservice = game:GetService("TweenService")
for i2, v2 in pairs(v.Parts:GetChildren()) do
local part = v2
local pos = part.Position --assuming you aren't using CFrame
local offset = 5 --5 studs per tween
local Info = TweenInfo.new(
0.1,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.InOut,
0,
false,
0
)
local IncreaseGoals = {
Position = Vector3.new(pos.X, pos.Y+offset, pos.Z)
}
local increaseTween = tweenservice:Create(part, Info, IncreaseGoals)
increaseTween:Play()
end
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local DefaultSize = script.Parent.Size
function determineClosest(EggsAvailable)
local CurrentClosest = nil
local ClosestDistance = script.Parent.MaxMagnitude.Value
for i,v in pairs(EggsAvailable) do
local Egg = workspace.Eggs:FindFirstChild(v)
local mag = (Egg.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
if mag <= ClosestDistance then
CurrentClosest = Egg
ClosestDistance = mag
end
end
return CurrentClosest
end
RS.RenderStepped:Connect(function()
if Player.Character:FindFirstChild("Humanoid") then
if Player.Character.Humanoid.Health ~= 0 then
local EggsAvailable = {}
local CameraRatio = ((Camera.CFrame.Position - Camera.Focus.Position).Magnitude)/11
script.Parent.Visible = false
for i,v in pairs(game.Workspace.Eggs:GetChildren()) do
local mag = (v.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
if mag <= script.Parent.MaxMagnitude.Value then
EggsAvailable[#EggsAvailable+1] = v.Name
end
end
if #EggsAvailable == 1 then
local Egg = workspace.Eggs:FindFirstChild(EggsAvailable[1])
local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
script.Parent.Visible = true
script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
script.Parent.CurrentTarget.Value = Egg.Name
for i,v in pairs(workspace.Eggs:GetChildren()) do
if v.Name ~= Egg.Name then
local tweenservice = game:GetService("TweenService")
for i2, v2 in pairs(v.Parts:GetChildren()) do
local db = true
local part = v2
local pos = part.Position --assuming you aren't using CFrame
local offset = 5 --5 studs per tween
local Info = TweenInfo.new(
0.1,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.InOut
)
local IncreaseGoals = {
Position = Vector3.new(pos.X, pos.Y-offset, pos.Z)
}
local increaseTween = tweenservice:Create(part, Info, IncreaseGoals)
if db == true then
db = false
increaseTween:Play()
end
increaseTween.Completed:Connect(function()
db = false
end)
end
v.Outline.Color = Color3.fromRGB(255,255,255)
else
v.Outline.Color = Color3.fromRGB(0,255,0)
end
end
elseif #EggsAvailable > 1 then
local Egg = determineClosest(EggsAvailable)
local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
script.Parent.Visible = true
script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
script.Parent.CurrentTarget.Value = Egg.Name
for i,v in pairs(workspace.Eggs:GetChildren()) do
if v.Name ~= Egg.Name then
v.Outline.Color = Color3.fromRGB(255,255,255)
else
v.Outline.Color = Color3.fromRGB(0,255,0)
end
end
elseif #EggsAvailable == 0 then
script.Parent.CurrentTarget.Value = "None"
for i,v in pairs(workspace.Eggs:GetChildren()) do
v.Outline.Color = Color3.fromRGB(255,255,255)
end
end
script.Parent.Size = UDim2.new(DefaultSize.X.Scale/CameraRatio, DefaultSize.X.Offset, DefaultSize.Y.Scale/CameraRatio, DefaultSize.Y.Offset)
end
end
end)
Never mind that doesn’t work I’d suggest just doing separate tweenings for each part and playing it at the same time
edit: I’ve tried it and there aren’t any heavy delays nor noticeable ones It’s actually very synced. (doing separate tweenings)
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local DefaultSize = script.Parent.Size
function determineClosest(EggsAvailable)
local CurrentClosest = nil
local ClosestDistance = script.Parent.MaxMagnitude.Value
for i,v in pairs(EggsAvailable) do
local Egg = workspace.Eggs:FindFirstChild(v)
local mag = (Egg.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
if mag <= ClosestDistance then
CurrentClosest = Egg
ClosestDistance = mag
end
end
return CurrentClosest
end
RS.RenderStepped:Connect(function()
if Player.Character:FindFirstChild("Humanoid") then
if Player.Character.Humanoid.Health ~= 0 then
local EggsAvailable = {}
local CameraRatio = ((Camera.CFrame.Position - Camera.Focus.Position).Magnitude)/11
script.Parent.Visible = false
for i,v in pairs(game.Workspace.Eggs:GetChildren()) do
local mag = (v.UIanchor.Position-Player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
if mag <= script.Parent.MaxMagnitude.Value then
EggsAvailable[#EggsAvailable+1] = v.Name
end
end
if #EggsAvailable == 1 then
local Egg = workspace.Eggs:FindFirstChild(EggsAvailable[1])
local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
script.Parent.Visible = true
script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
script.Parent.CurrentTarget.Value = Egg.Name
for i,v in pairs(workspace.Eggs:GetChildren()) do
if v.Name ~= Egg.Name then
local tweenservice = game:GetService("TweenService")
for i2, v2 in pairs(v.Parts:GetChildren()) do
local db = true
local part = v2
local pos = part.Position --assuming you aren't using CFrame
local offset = 5 --5 studs per tween
local Info = TweenInfo.new(
0.1,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.InOut
)
local IncreaseGoals = {
Position = Vector3.new(pos.X, pos.Y-offset, pos.Z)
}
local increaseTween = tweenservice:Create(part, Info, IncreaseGoals)
if db == true then
db = false
increaseTween:Play()
end
increaseTween.Completed:Connect(function()
db = false
end)
end
v.Outline.Color = Color3.fromRGB(255,255,255)
else
v.Outline.Color = Color3.fromRGB(0,255,0)
end
end
elseif #EggsAvailable > 1 then
local Egg = determineClosest(EggsAvailable)
local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(Egg.UIanchor.Position)
script.Parent.Visible = true
script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
script.Parent.CurrentTarget.Value = Egg.Name
for i,v in pairs(workspace.Eggs:GetChildren()) do
if v.Name ~= Egg.Name then
v.Outline.Color = Color3.fromRGB(255,255,255)
else
v.Outline.Color = Color3.fromRGB(0,255,0)
end
end
elseif #EggsAvailable == 0 then
script.Parent.CurrentTarget.Value = "None"
for i,v in pairs(workspace.Eggs:GetChildren()) do
v.Outline.Color = Color3.fromRGB(255,255,255)
end
end
script.Parent.Size = UDim2.new(DefaultSize.X.Scale/CameraRatio, DefaultSize.X.Offset, DefaultSize.Y.Scale/CameraRatio, DefaultSize.Y.Offset)
end
end
end)