I’m trying to better optimize my game by using tags, here’s my old script for reference.
Old Script:
--fyi parts of the code have been snipped out in this post
local UserInputService = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local WhitelistedTooltipItems = {"Takeaway Lid", "Takeaway Sleeve", "Bowl of Cherries", "Cold Drink Lid"}
if not UserInputService.TouchEnabled then
Mouse.Move:Connect(function()
local Target = Mouse.Target
if Target and Target.Parent then
if table.find(WhitelistedTooltipItems, Target.Parent.Name) then
if (Player.Character.UpperTorso.Position - Target.Parent.TextHitbox.Position).Magnitude < ItemMagnitude and (Head.CFrame.p - Camera.CFrame.p).Magnitude < CameraMagnitude then
Tooltip.Visible = true
end
end
end
end)
end
Hopefully you kinda understood the jest of what I was doing there, but I wanted to switch over to using tags, it it possible to do so? I have one tag called “test” so do what you will!
I know how to use the method GetTagged. In fact I use it many times through out my game.
I’m not to sure what you mean by that.
Some more explanation is a I have a many model’s in workspace that are tagged with "test" and I don’t want to have to always update the script when I change the models names. So I am using tags! Could you show me an example of what you meant by the quote above though?
I meant that you would have a static list of GetTagged("test") and then you would iterate through it and check each one and determine if it matches what the mouse is pointing at.
for _, taggedObject in pairs(CollectionService:GetTagged("test")) do
if taggedObject == Target.Parent and (Player.Character.UpperTorso.Position - Target.Parent.TextHitbox.Position).Magnitude < ItemMagnitude and (Head.CFrame.p - Camera.CFrame.p).Magnitude < CameraMagnitude then
Tooltip.Visible = true
end
end