Table not working

Hey Everyone,
I’m making it so that developers for my story game get instantely respawned, here is my script:

local Developers = {'1486279975', '1381724234'}

local MarketplaceService = game:GetService("MarketplaceService")
local diedEvent = game.ReplicatedStorage.DiedEvent
local reviveEvent = game.ReplicatedStorage.reviveEvent

game.Players.CharacterAutoLoads = false

function loadDiedFunction(player)
	player.Character.Humanoid.Died:connect(function()
		for i,v in pairs(Developers) do
			if v == player.UserId then
				player:LoadCharacter()
			else
				wait(1)
				diedEvent:FireClient(player)
			end
		end
	end)
end

I get no errors, however the death screen still appears and they don’t get respawned.
Thanks for any help.

1 Like

Nevermind, I just removed the ’ and it worked.

Yeah I was about to say the same, im glad you noticed it! :smiley:

Wait, do you know why the GUI Is popping up anyway? It respawns the player and then pops up.

I just commented out the

diedEvent:FireClient(player)

And it didn’t appear, so It must be firing anyway, any idea why?

Because of 1486279975 and 1381724234.
One of them is your UserId. The other one is not.
it checks if the UserId is correct since both UserId’s cant be your its causing the else to run
I recommend to put a return.

function loadDiedFunction(player)
	player.Character.Humanoid.Died:connect(function()
		for i,v in pairs(Developers) do
			if v == player.UserId then
				player:LoadCharacter()
                return
			else
				wait(1)
				diedEvent:FireClient(player)
			end
		end
	end)
end

I hope this is correct :joy:

Yep, it fixed it…

1 Like

This will cause it to still run if the first UserId isn’t their’s, but the second is. A better solution would be to search the whole table for their UserId before FireClienting. You can do this with a simple table.find:

-- instead of the whole loop
if table.find(Developers, player.UserId) then
	player:LoadCharacter()
else
	wait(1)
	diedEvent:FireClient(player)
end

Relevant docs: table | Documentation - Roblox Creator Hub (it’s the last one)

4 Likes