I’m currently making a radial selection menu, however I’m trying to tween the line that points towards what you’re selecting only issue is I’m having an issue with tween service and it snapping around.
If you have any ways I can negate this effect or remove it entirely then please inform me.
Thanks!
Here’s the code I’m using for this:
--vars
local Area = script.Parent.Area
local Center = Area.Center
local PointLine = Center.PointLine
local Buttons = Area.Buttons
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local UIS = game:GetService("UserInputService")
local REPLICATED_STORAGE = game:GetService("ReplicatedStorage")
local TWEEN_SERVICE = game:GetService("TweenService")
local HTTP_SERVICE = game:GetService("HttpService")
local open = false
local lastRotTween = false
-- events
local INVENTORY_EVENT_FOLDER = REPLICATED_STORAGE:WaitForChild("Inventory")
local EVENTS = {
["updateInventory"] = INVENTORY_EVENT_FOLDER:WaitForChild("updateInventory"),
["serverCheck"] = INVENTORY_EVENT_FOLDER:WaitForChild("serverCheck"),
["clientCheck"] = INVENTORY_EVENT_FOLDER:WaitForChild("clientCheck"),
}
-- modules
local INVENTORY_MODULE = require(script:WaitForChild("Inventory"))
-- functions
-- base functions
do
baseFunctions = {}
function baseFunctions.GetAngle(v1,v2)
local dif = (v1-v2)
local r = math.atan2(dif.Y,dif.X) --* (180 / math.pi)
return math.deg(r)
end
function baseFunctions.UpdatePointLine()
local mp = UIS:GetMouseLocation()
local angle = baseFunctions.GetAngle(mp,Center.AbsolutePosition)
TWEEN_SERVICE:Create(PointLine,TweenInfo.new(0.15,Enum.EasingStyle.Linear),{Rotation = angle}):Play()
end
end
-- main functions
do
mainFunctions = {}
function mainFunctions.setupServerConnection()
EVENTS.serverCheck.OnClientEvent:Connect(function(key)
EVENTS.serverCheck:FireServer({key,INVENTORY_MODULE})
end)
end
function mainFunctions.requestPlayerInventory()
local key = HTTP_SERVICE:GenerateGUID(false)
local ans = EVENTS.updateInventory:InvokeServer(key)
repeat wait() until ans
if ans["key"] == key then
INVENTORY_MODULE["Inventory"] = ans["newInv"]
end
end
function mainFunctions.collidesWith(gui1, gui2) ---A little different wording but it serves the same purpose
local gui1_topLeft = gui1.AbsolutePosition
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y))
end
end
local module = {}
function module.init()
task.spawn(mainFunctions.setupServerConnection())
mainFunctions.requestPlayerInventory()
end
function module.callServerCheck()
end
function module.runUpdates()
repeat
baseFunctions.UpdatePointLine()
for _,v in pairs(Area.Buttons:GetChildren()) do
if mainFunctions.collidesWith(PointLine.Tip,v) then
TWEEN_SERVICE:Create(v,TweenInfo.new(0.15,Enum.EasingStyle.Linear),{Size = UDim2.new(0.172, 20,0.172, 20)}):Play()
else
TWEEN_SERVICE:Create(v,TweenInfo.new(0.15,Enum.EasingStyle.Linear),{Size = UDim2.new(0.172, 0,0.172, 0)}):Play()
end
end
wait()
until open == false
end
function module.toggleInventory(v)
if v == false then
UIS.MouseIconEnabled = true
open = false
Area:TweenSizeAndPosition(UDim2.new(0,0,0,0),UDim2.new(0.5,0,2,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,0.5)
elseif v == true then
--UIS.MouseIconEnabled = false
open = true
task.spawn(function()
module.runUpdates()
end)
Area:TweenSizeAndPosition(UDim2.new(0.252, 0,0.499, 0),UDim2.new(0.5,0,0.5,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,0.5)
end
end
return module