Does plr.PlayerRemoving detect plr:Kick()?

Hello, do you know if when you kick a player

plr:Kick('SORRY, ROBLOX DATA IS BUGGED PLEASE TRY TO JOIN LATER!')

Player Removing function gonna detect that the player has been kicked and run the function ?

Players.PlayerRemoving:Connect(function(plr)
	local Data = {
	}
	SaveData:SetAsync(plr.UserId, Data)
end)

Thank you for your help

No, Not always, thats the reason’s people recommend having game:BindToClose when saving Data under DataStoreService, so if something happens and PlayerRemoving Doesnt work, BindToClose will save it to ensure you dont lose data.

If you have a Active Server, it should still save depending on how you handle the data.

But then all these datastores I see are not good ? Developers tend to kick the player if the data doesn’t load to avoid to save an erroned data, but it the plr.PlayerRemoving is launched it doesn’t make sense because the player will save an empty data ?

People check if the Data exists if Getting the Data was Successful, like this:

local sessions = {} -- Session Holder
-- PlayerAdded :

if success then -- If GetAsync was successful
    if data then -- if there is data
        sessions[player.UserId] = data -- Adds Data to a Session Holder
    else -- if there is no data
        sessions[player.UserId] = {...}
    end
    
else -- If Failed
   player:Kick"Something went wrong!" 
end


-- PlayerRemoving :

if sessions[player.UserId] then -- if there is a session to save
    -- save data
end

1 Like

I understand better now. No one mentions this in their script. Thanks for your help

You forgot the brackets after Kick!

It still works either way, you can do the same with print

print"This works"

print("This also works")

and with GetService or FindService

local DSS = game:GetService"DataStoreService"

However the downside is that you can’t add variables, or Arguments, which is why you use the Parenthesis

Oh, I don’t know that, but I would still add brackets anyway

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.