As the title suggests I’m trying to make a system that just punishes players for leaving in the middle of a round. I’m making a round based system with killstreaks, rewards, and stats such as total wins, levels, ect. And I’d have for people to have lets say a killstreak of 7 and see they’re going to lose and leave to avoid the consequences. I’ve tried a few systems thus far and everything fires too late. I basically want to edit a player’s DataFolder (Under the player) before they leave, either edit it entirely as they leave or give them a new value which then punishes them when they rejoin. Nothing so far has worked, so if you can think of anything, or have any sort of advice or help, it’d mean the world. I’m very close to releasing my first game and I want it to be as well thought out as possible.
it applies the reward money to the remaining player just fine, but it doesn’t affect the other players data. I know for a fact that the DataAPI system works because in a different function it works just great. So how can I make it work for me here too?
As I said, any and all help means the world. Thank you for your time, patience and attention.
Have a great rest of your day, take care of yourself and others, and stay safe.
This happens because PlayerRemoving runs while Roblox is already cleaning the player up, so their DataFolder and references aren’t very reliable at that point.
A better way is to track if they’re in a round while they’re still playing.
When the round starts, you mark them:
player:SetAttribute("InRound", true)
When the round ends normally you clear it:
player:SetAttribute("InRound", false)
Then in PlayerRemoving you just check the flag instead of trying to edit their live data:
Players.PlayerRemoving:Connect(function(player)
if player:GetAttribute("InRound") then
-- mark them as a leaver in your datastore
end
end)
And when they join back, you handle the punishment there:
Players.PlayerAdded:Connect(function(player)
-- check if they were marked as a leaver
-- apply punishment here
end)
So instead of trying to change their stats as they leave, you flag it and deal with it when they rejoin :).
Thank you Taco, I’ll be trying this right now and I’ll let you know how it turns out. It’s currently almost 3AM for me so if I don’t reply tonight, that’s why. Thank you for your time and help, I’m not the best at scripting, I’m a solo developer so I can do everything from Animation and Modeling to Music and Scripting but I am not amazing at any of it.
I also do everythinggg, I am quite sure this will work, programing/scripting has been my thing for 8+ years so I would hope I have that down, make sure to reply if it doesn’t work, I’d love to help you ^_^, have a great sleep!
In the end I basically was able to do what you did, all I did was added a new value under the player called InRound, made it a num value and set it at 0 default, and at the start of a round, it changes to 1, and if you leave, the value saves and remains unchanged, so if you join, a server script detects the value and punishes you then. Thank you Taco!
I suggest applying some kind of grace period. What if the player’s internet connection crapped out and they got disconnected, or what if their hardware had crashed and they’re restarting their PC?
That’s the issue, roblox isn’t very good at that. It can’t really decipher whether someone disconnects, hits alt + F4, or wifi goes out. Unless I’m wrong and I COULD detect difference, I just don’t know. By keeping it strict there aren’t any work arounds either. Lets say someone sees they’re about to lose, they’ll just disable the wifi on their computer and the game will pity them and leave it at that. Theoretically I could just apply the money and other values when the game behind the scenes decides whether someone wins or loses, and that’d solve the issue of leaving the game on death, but that still leaves the grey areas of using that system against the game, you know what I mean? Frankly this is what I get for making games on roblox.