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.
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
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