So lets just say I have one table and lets call it targets. Now I want to add a player name to targets. So I add in a player name to targets every time someone hovers over a Click detector. Now I don’t want it so that their name gets added over and over again to the table if they keep hovering over it. I want it to check if their name is already in the table. How Do I Achieve This? Sorry if I’m asking a stupid question its just something I can’t seem to figure out.
If You Know Anything About This Feel Free To Reply!
local targets = {} -- Target table
local clickDetector = script.Parent.ClickDetector -- Click detector
local function hoveringMouse(player)
if player.Name ~= table.unpack(targets) -- This tries to find player name in [target] table then
table.insert(targets,player.Name) -- This inserts player's name in target list
print(table.unpack(targets))
else
return
end
end
clickDetector.MouseHoverEnter:Connect(hoveringMouse)
This does not work I don’t know why and when I remove the if statement it works again. There were no errors btw.
Here are some screenshots:
(without if statement)
Thank you for answering my stupid quarry. The reason why I posted this was because the table.find was not working and I did not really think of using table.unpack