Value In Datastore not updating

The value BanDuration inside of the datastore is not updating when I run the unban function. Can someone help me figure out why.



local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DDS = game:GetService("DataStoreService");
local Players = game:GetService("Players");

local BanFunction = ReplicatedStorage:WaitForChild("Ban")

local BanStore = DDS:GetDataStore("BanStore", 2) 
local secondsInADay = 86400

local unbanRemote = ReplicatedStorage:WaitForChild("Unban")


function BanFunction.OnServerInvoke(PlayerSentBy, Player, Reason, Duration)
	local Success, Error = pcall(function() 
		BanStore:SetAsync(tostring(Player.UserId), {BanStart = os.time(), BanDuration = (Duration * secondsInADay), BanReason = Reason});
	end)
	Player:Kick(Reason);
	if not Success then 
		warn("Not successful.")
	end
end

function unbanRemote.OnServerInvoke(PlayerSentBy, Player, Duration)
	BanStore:SetAsync(tostring(Player.UserId), {BanDuration = 0})
end


local function GetBan(Player)
	local banData = BanStore:GetAsync(tostring(Player.UserId))
	if banData and banData.BanDuration > 0 and banData.BanStart + banData.BanDuration > os.time() then
		return banData.BanReason
	end
	return nil
end

Players.PlayerAdded:Connect(function(plr)
	local IsBanned = GetBan(plr);
	
	if IsBanned ~= nil then
		plr:Kick("You are banned for ".. IsBanned);
	else

	end
end)


could you share the clientside code that’s invoking the remotes too?

Your server end looks good, I’d consider taking a look at your client end.

Potential Issue

  • “BanStore” has a timeout of 2 seconds, consider increasing

This may not be enough time to retrieve the data varying on cases. This is potentially prone to errors.

I figured it out, I passed the wrong player parameter.

1 Like

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