Calling Instance from table

  1. What do you want to achieve?
    I am working on some local script. That local script is being cloned into the player’s character upon joining/respawning. Then the variable referenced to the cloned script is put into a table. Every X seconds, the server checks if the script is still there with the earlier inserted table value.

  2. What is the issue? Include screenshots / videos if possible!
    Well, the table value isn’t nil and stuff it works as it should, but every time I try to see if it is there, the script says it isn’t. I’m not sure if I correctly set the if statement up but I am lost now…

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking on the dev forum and trying to figure things out myself but nothing helped.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

The script:

local ReportRemote = script.ReportDetection
local LocalDetection = script.LocalDetection

ReportRemote.Parent = game:GetService("ReplicatedStorage")

local References = {}

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local ClonedScript = LocalDetection:Clone()
		ClonedScript.Parent = character
		ClonedScript.Name = HttpService:GenerateGUID(false)
		
		References[player.UserId] = ClonedScript
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	References[player.UserId] = nil
end)

while task.wait(10) do
	for _,player in pairs(game:GetService("Players"):GetPlayers()) do
		if player.Character then
			if not player.Character.References[player.UserId] then
				print("Not found")
			else
				print("found")
			end
		end
	end
end

You should be able to just check References[player.UserId]. I’m not sure why you’re trying to index the table inside of the player’s character, the table isn’t in the character…

You should also probably check for the parent instead of just not References[player.UserId] because if the client deletes the script from their character, it will be parented to nil on the server and your not check will still be returning true.

Oh yea, you’re right. I fixed it that way. Thank you.
Another issue is I just wanted to also check if it is disabled but that doesn’t work:

while task.wait(10) do
	for _,player in pairs(game:GetService("Players"):GetPlayers()) do
		if player.Character then
			if References[player.UserId].Parent ~= player.Character or References[player.UserId].Disabled == true then
				print("Not found")
			else
				print("found")
			end
		end
	end
end

.Disabled isn’t replicated from client to server

I just realized that, alright thank you very much for your help. Learned another thing today!