Note: I’m kinda new to roblox scripting
What I’m trying to do is check if a meme has been collected already and if it hasn’t, the if statement will go on. But for some reason the if statement always goes on even if the meme is already inside the table.
Code:
local remote = game:GetService("ReplicatedStorage"):WaitForChild("Remote")
local memesCollected = {}
for _, meme in pairs(workspace.Memes:GetChildren()) do
meme.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if not memesCollected[player] then -- if player doesn't have a table
memesCollected[player] = {}
end
if not memesCollected[player][meme.Name] then -- if meme isn't already collected (doesn't work for some reason)
local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
table.insert(memesCollected[player], meme.Name)
remote:FireClient(plr, meme, true)
end
end
end)
end
Ask me anything!