Hey, does anyone know if I can type anything into the command bar, to unban myself from my own game, and how to respawn a player in my script when they get unbanned, and at 0hp, and the respawn time is set to infinite?
The way this script works is that if you die, you get banned for 24 hours (sword fight game). You have a option to buy a dev product to get unbanned, else you get banned for 24 hours.
-- Variables
local DataStoreService = game:GetService("DataStoreService")
local key = "PlayersWhoHaveDied"
local deathStore = DataStoreService:GetDataStore(key)
local PlayerService = game:GetService("Players")
local wasPurchased
local productid = 1215988684
local marketplace = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
-- Events
PlayerService.PlayerAdded:Connect(function(player)
local id = player.UserId
local success, val = pcall(function()
return deathStore:GetAsync(id)
end)
print(val)
if success and val then
print(os.time() - val)
if os.time() <= val then
local kickMessage = os.date("You can play again at %c", val)
player:Kick(kickMessage)
else
print("dam")
deathStore:RemoveAsync(id)
end
end
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")
hum.Died:Connect(function()
marketplace:PromptProductPurchase(player,productid)
marketplace.PromptProductPurchaseFinished:Connect(function(player, purchase_id, was_purchased)
if was_purchased == true then
print("Unbanning")
-- respawn player here HELPPP
else
print("Banning")
deathStore:SetAsync(id, os.time() + 86000)
player:Kick("You have been banned for 24 hours!")
print("Banned")
end
end)
end)
end)
Appreciate it, the unban worked, also the way the dev product works is that if you die, you get a dev product prompt purchase, and if you accept it, then you would get respawned, but if you declined it would ban you.
For some reason, I’m getting this error, when it’s trying to kick the player.:
ServerScriptService.BanHandler:56: attempt to index number with ‘Kick’
-- Variables
local DataStoreService = game:GetService("DataStoreService")
local key = "PlayersWhoHaveDied"
local deathStore = DataStoreService:GetDataStore(key)
local PlayerService = game:GetService("Players")
local wasPurchased
local productid = 1215988684
local marketplace = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
-- Events
PlayerService.PlayerAdded:Connect(function(player)
local id = player.UserId
local success, val = pcall(function()
return deathStore:GetAsync(id)
end)
print(val)
if success and val then
print(os.time() - val)
if os.time() <= val then
local kickMessage = os.date("You can play again at %c", val)
player:Kick(kickMessage)
else
print("dam")
deathStore:RemoveAsync(id)
end
end
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")
hum.Died:Connect(function()
marketplace:PromptProductPurchase(player,productid)
marketplace.PromptProductPurchaseFinished:Connect(function(player, purchase_id, was_purchased)
if was_purchased == true then
print("Unbanning")
-- respawn player here plr:LoadCharacter()
else if was_purchased == false then
print("Banning")
deathStore:SetAsync(id, os.time() + 86000)
player:Kick("You have been banned for 24 hours!")
end
end
end)
end)
end)
was_purchased seems to be working, it prints true when purchased, and false if cancelled, its something to do with the kick thing, i dont know what it is, was working before - can link you the game
The PromptProductPurchaseFinished when fired emits 3 values to any function connected to it, those being userId, productId & an isPurchased state. https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptProductPurchaseFinished
So the call to the Kick() function on that line is being attempted on the player’s user ID as opposed to the player’s instance itself. To fix that you could simply use the following:
PlayerService:GetPlayerByUserId(player):Kick("You have been banned for 24 hours!")
This sounds like you’re just ripping off my game, If you OOF you get BANNED. It took me a LONG time to come up with the idea, please don’t blatantly steal it from me.
I’m surprised you even saw this topic, I’m just doing it for fun honestly, since I’m bored - but you’re not necessarily the first person to think of this, but I still respect you. It won’t get on your level, I’m just liking on creating this because of how simplistic but fun it is. I hope that you can understand me. Even if I do make it and publish it, you will get credits but I won’t be spending racks on advertising - like you did.