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

How can i make my datastore for bans work? Am i missing something?

Just wanted to make a ban datastore today, and i feel like i'm missing something on the code. Seems to not work in roblox with api services enabled. <--- Problem

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("BanDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "PlayerValues"
	
	local banvalue = Instance.new("BoolValue",folder)
	banvalue.Value = false
	banvalue.Name = "BanValue"

end)


		--SetAsync.Ban
	game.Players.PlayerRemoving:Connect(function(player)
	if player.PlayerValues.BanValue.Value == true then
		ds1:SetAsync(player.UserId, player.PlayerValues.BanValue.Value)
		
	
--BanCheck
ds1:GetAsync(player.UserId, player.PlayerValues.BanValue.Value)
		if player.PlayerValues.BanValue.Value == true then
			player:Kick("Banned.")
		end
		end
		end)

3 comments

0

Funny that you say that, I am writing a ban system for my game using data stores.

0

^ Good luck writing it mate.

0

I know.

1 answer

✓ Accepted answer
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("BanDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "PlayerValues"

	local banvalue = Instance.new("BoolValue",folder)
	banvalue.Value = false
	banvalue.Name = "BanValue"

	ds1:GetAsync(player.UserId, player.PlayerValues.BanValue.Value)
      	if player.PlayerValues.BanValue.Value == true then
        	player:Kick("Banned.")
        end
end)

--SetAsync.Ban
game.Players.PlayerRemoving:Connect(function(player)
	ds1:SetAsync(player.UserId, player.PlayerValues.BanValue.Value)
end)

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