Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my code freeze after saving data?

I need some help. When I try to save data, the code after the save line doesn't work. I need some help, does anyone know why this doesn't work? The data doesn't save and the code stops.

game.Players.PlayerRemoving:Connect(function(player)
	print("a player left")
	local teamName = player.Team.Name
	local success, error = pcall(function()
		myDataStore:SetAsync(player.UserId.."-team",teamName)
	end)
	
	if success then
		print("success")
	else
		warn(error)
	end
end)

1 comment

0

Did you define myDataStore?

1 answer

✓ Accepted answer

It's because "error" is a thing already part of roblox ( I dont know what its called) which means you cant use it, change "error" to "errorMessage"

game.Players.PlayerRemoving:Connect(function(player)
    print("a player left")
    local teamName = player.Team.Name
    local success, errorMessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-team",teamName)
    end)

    if success then
        print("success")
    else
        warn(errorMessage)
    end
end)

3 comments

0

Thanks dude I'm a newb.

0

but I just noticed that sometimes it works and sometimes it stops there

0

It's known as a reserved identifier; it's registered as a global built-in.

This discussion is preserved as it was. New answers, comments, and votes are closed.