Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I cannot remove myself from datastore of banned players?

Asked by 2 years ago
local circle = script.Parent
local players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local bannedStore = DataStoreService:GetDataStore("BannedPlayers")

local function getBan(player)
    if bannedStore:GetAsync(player.UserId) then
        return true end
    return false
end


local function checkBan(player)
    if getBan(player) then
        player:Kick("Please do not come back as you failed.")
    end
end

local function CircleExtending()
    circle.Size += Vector3.new(0,5,5)
end

local function CircleShrinking(player)
    circle.Size -= Vector3.new(0,50,50)
    bannedStore:SetAsync(player.UserId, true)
    player:Kick("You have failed this event, thank you for attending.")
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(function ()
        CircleExtending()
        checkBan(player)
    end)
    player.CharacterRemoving:Connect(function ()
        CircleShrinking(player)
    end)
    player.PlayerRemoving:Connect(function ()
        CircleShrinking(player)
    end)
end

players.PlayerAdded:Connect(onPlayerAdded)

I try running bannedStore:RemoveAsync(my id) but it says 'attempt to index nil' I know it can't be nil because It kicks me when I join, my friend is also banned and I cannot remove him too

0
That's some screwed power your code has! greatneil80 2647 — 2y
0
Ah... well, either you do SetAsync(id, false) or just change it by a datastore plugin. Or delete the script.. AProgrammR 398 — 2y

1 answer

Log in to vote
0
Answered by
X_Z 0
2 years ago

This function seems to be banning and kicking everyone regardless.

local function CircleShrinking(player)
    circle.Size -= Vector3.new(0,50,50)
    bannedStore:SetAsync(player.UserId, true) --Ban
    player:Kick("You have failed this event, thank you for attending.") --Kick
end

You call this function whenever a client's character is removed or when the player leaves the game effectively banning everyone after their first play of your game. Change this to stop everyone from being banned

player.CharacterRemoving:Connect(function ()
    CircleShrinking(player)
end)
player.PlayerRemoving:Connect(function ()
    CircleShrinking(player)
end)

For unbanning yourself and your friends I recommend using :RemoveAsync() or doing a manual :SetAsync(UserId,false)

Ad

Answer this question