DataStore Bool Value Help

I am trying to make a ban appeal system, When the player submits the ban appeal, It fires a RemoteEvent and the remote event saves to the DataStore with the BoolValues value being true, When the player joins, if the BoolValue is set to true, It fires a different RemoteEvent to the client side, showing a different UI, However it doesn’t work and I was wondering if somebody count help me.

Server Script:

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("BanAppeals")

Players.PlayerAdded:Connect(function(Player)
	local BoolValue = Instance.new("BoolValue")
	BoolValue.Name = "HasAppealPending"
	BoolValue.Parent = Player
end)

game.ReplicatedStorage.SendAppeal.OnServerEvent:Connect(function(Player)
	local BoolValue = Player:FindFirstChild("HasAppealPending")

	if BoolValue and not BoolValue.Value then
		BoolValue.Value = true
		DataStore:SetAsync(Player.UserId, true)
		game.ReplicatedStorage.AppealPending:FireClient(Player)
	end
end)

LocalScript:
Submitting the appeal

local function SubmitAppeal()
	local LocalPlayer = game:GetService("Players").LocalPlayer
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	
	ReplicatedStorage.SendAppeal:FireServer(Answer1.Text, Answer2.Text, Answer3.Text, Answer4.Text)
	LocalPlayer:WaitForChild("HasAppealPending").Value = true
	LocalPlayer:Kick("Appeal Successfully Sent!")
end

Form.Submit.MouseButton1Click:Connect(SubmitAppeal)

What happens when the Client Event is fired:

local function AppealPending()
	Home.Visible = false
	Pending.Visible = true
end

game.ReplicatedStorage.AppealPending.OnClientEvent:Connect(function()
	AppealPending()
end)
2 Likes

Your script is mostly complete, however you’re missing a couple of key components:

  • Initialize the Player’s Appeal Status from DataStore: When the player joins, check the DataStore to see if they have an appeal pending and set the BoolValue accordingly.
  • Send Notification to Client on Join: If the player has an appeal pending, notify the client immediately.
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("BanAppeals")

-- Function to handle player joining
local function onPlayerAdded(Player)
    local BoolValue = Instance.new("BoolValue")
    BoolValue.Name = "HasAppealPending"
    BoolValue.Parent = Player
    
    -- Retrieve the appeal status from DataStore
    local success, appealPending = pcall(function()
        return DataStore:GetAsync(Player.UserId)
    end)
    
    -- If retrieval was successful and appeal is pending, update the BoolValue
    if success and appealPending then
        BoolValue.Value = true
        game.ReplicatedStorage.AppealPending:FireClient(Player)
    else
        BoolValue.Value = false
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)

-- Handle appeal submission
game.ReplicatedStorage.SendAppeal.OnServerEvent:Connect(function(Player)
    local BoolValue = Player:FindFirstChild("HasAppealPending")
    
    if BoolValue and not BoolValue.Value then
        BoolValue.Value = true
        DataStore:SetAsync(Player.UserId, true)
        game.ReplicatedStorage.AppealPending:FireClient(Player)
    end
end)
1 Like

I’ll give that a try next time I’m in studio, Thanks!

It worked! Thank you so much. I’ve been trying to do this for a while.

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