I have trouble with a player getting kicked, if a value is greater than another value.
In this circumstance, the players value is greater than 0 but does not get kicked whilst joining (Kind of like a ban scheme.)
If anyone has any fixes, please lemme know.
game.Players.PlayerAdded:Connect(function(player)
local Increment = player:WaitForChild("Stats"):FindFirstChild("Increment").Value
print(Increment)
if Increment >= 1 then
player:Kick()
else
end
end)
Actually, there is a separate script, (if you want it you can tell me) where it increases the players amount so the next time a person joins they get auto kicked, but it seems as if data doesn’t save
local PS = game:GetService("Players")
PS.PlayerAdded:Connect(function(player: Player)
local stats = player:FindFirstChild("Stats")
local increment = stats and stats:FindFirstChild("Increment")
warn(increment.Value)
if increment and increment.Value >= 1 then
player:Kick()
end
end)
So, if the player talks it sends an remote event to the client, and then to the server back. (But there are decorations in client) Though the data is not updating for some reason?
local IncrementVal = game:GetService("ReplicatedStorage"):WaitForChild("IncrementVal")
function onListenEvent(player)
local Increment = player:WaitForChild("Stats"):WaitForChild("Increment")
Increment.Value += 1
print(Increment.Value)
end
IncrementVal.OnServerEvent:Connect(onListenEvent)
The code that “Kicks” the player only run once, so it will never get kicked if you increment the value after the code that “Kicks” already runned.
local Data = game:GetService("DataStoreService"):GetDataStore("statStore")
game.Players.PlayerAdded:Connect(function(player)
local s = Instance.new("Folder",player)
s.Name = "Stats"
local u = Instance.new("NumberValue",s)
u.Value = 0
u.Name = "Revivals"
local i = Instance.new("NumberValue",s)
i.Value = 0
i.Name = "Increment"
local dataload = Data:GetAsync(tostring(player.UserId))
if dataload then
u.Value = dataload[1] or 0
i.Value = dataload[2] or 0
end
game.Players.PlayerAdded:Connect(function(player)
Data:SetAsync(tostring(player.UserId),{
player.Stats.Revivals.Value,
player.Stats.Increment.Value
})
end)
end)
If you are using a datastore, it will first run that code and after that load the datastore. The problem is that you are trying to kick a player with a value in the server that loads after the code “PlayerAdded” already runned, instead of using a value, Use “GetAsync()” to see if the datastore of the Player has change.