So I made an Interaction system but whenever I press the Key meant to interact even if I’m not hovering over an interaction part the game’s fps drops like crazy for a few seconds. I would appreciate if anyone can help me.
Here is my script used to do the Interactions
local CollectionService = game:GetService("CollectionService") local UIS = game:GetService("UserInputService") local mouse = game.Players.LocalPlayer:GetMouse() local player = game.Players.LocalPlayer local character = player.CharacterAdded:Wait() while wait(0.1) do if CollectionService:HasTag(mouse.Target, "Interactable") and (character.HumanoidRootPart.Position - mouse.Target.Position).Magnitude <= 6 then local Interaction = require(mouse.Target.Interaction) local description = Interaction.GetDescription() player.PlayerGui.ScreenGui.Key.Visible = true player.PlayerGui.ScreenGui.Key.Description.Text = description UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E and CollectionService:HasTag(mouse.Target, "Interactable") then Interaction.Interact() end end) else player.PlayerGui.ScreenGui.Key.Visible = false end end
Edit: It only seems to happen when the game has been running for a bit, also it only happens when I’m interacting now.