I currently have this simple script, but I am trying to understand if it always works like this, how/which parts get prioritized to get selected in the magnitude range?
I also use CollectionService to get all these parts.
local cs = game:GetService("CollectionService")
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.E and not gameProcessed then
for _,Interactable in pairs(cs:GetTagged("Interactable")) do
local Magnitude = (Interactable.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Magnitude <= 10 then
print(Interactable.Name)
end
end
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
script.Parent.InteractionPrompt.Visible = false
for _,Interactable in pairs(cs:GetTagged("Interactable")) do
local Magnitude = (Interactable.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Magnitude <= 10 then
local coords2D = game.Workspace.CurrentCamera:WorldToScreenPoint(Interactable.Position)
script.Parent.InteractionPrompt.Position = UDim2.new(0, coords2D.X, 0, coords2D.Y)
script.Parent.InteractionPrompt.Visible = true
end
end
end)
Is this a good method cause I don’t know anything else lol.