So i made a "E to interact" localscript. The table "interactables" is where the objects that i want the player to interact are stored :
--VARIABLES local plr = game.Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local mouse = plr:GetMouse() mouse.TargetFilter = workspace:WaitForChild("Terrain") local interactDistance = 5 local canInteract = false local interactables = {workspace.Can, workspace.Poubelle} repeat wait() until plr.Character ~= nil local char = plr.Character local debounce = false game:GetService("UserInputService").InputBegan:connect(function(key) if debounce == true then return end debounce = true if key.KeyCode == Enum.KeyCode.E and canInteract == true then if objName == "Can" then local takeTrashEvent = ReplicatedStorage:WaitForChild("TakeTrashEvent") takeTrashEvent:FireServer(obj) end end debounce = false end) while wait() do for i, part in pairs(interactables) do if (part.Position - char.UpperTorso.Position).magnitude < interactDistance and mouse.Target == part then canInteract = true objName = part.Name obj = part plr.PlayerGui.HUD.Tooltip.Text = "Press E to take ".. part.Name if part.Name == "Poubelle" then plr.PlayerGui.HUD.Tooltip.Text = ("Press E to throw your wastes".." ("..obj.Space.Value.." / "..obj.MaxSpace.Value..")") end plr.PlayerGui.HUD.Tooltip.Visible = true else canInteract = false plr.PlayerGui.HUD.Tooltip.Visible = false end end end
But when I test the game, the Tooltip (Press E to take...) only shows up when I look at the 2nd object stored in the table...