Constantly checking if the values are there

Hey! I’m trying to make a warning system but I couldn’t check if the value is there or not.

local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Warn1 = Instance.new("IntValue")
		Warn1.Name = "WarnCount"
		Warn1.Value = 0

		local Warn2 = Instance.new("StringValue")
		Warn2.Name = "WarnReason"
		
		Warn1.Parent = Character
		Warn2.Parent = Character
		
		while true do
			if not Character:FindFirstChild("Warn1") or not Character:FindFirstChild("Warn2") then
				Player:Kick("Something went wrong.")
				break
			end
		end
	end)
end)

Hello,

There are multiple issues in this block of code, but for now I will help you with the current issue of checking warnings.

In the block of code, you are creating values under the player’s character, which can be destroyed when they die, fall off the map, etc.

If you are trying to save the warnings throughout the entirety of the game, you should create and modify the values under the player’s name.

Is this what you’re trying to achieve?

Yes. If it’s not there, player will be kicked.

Would I be correct assuming the issue you are currently having is that the player is getting kicked immediately?

The issue is the player is not being kicked.

The only issue I have found that would make it not work is in this line

if not Character:FindFirstChild(“Warn1”) or not Character:FindFirstChild(“Warn2”) then

As “Warn1” and “Warn2” aren’t the names of the 2 values, you would also need some kind of wait or delay in the while true loop.

Alright cool.

Based on your script, it seems that you are trying to kick players for not having the values.
This will not kick the player because it will always ensure that they have the values.

game.Players.PlayerAdded:Connect(function(Player)
    local Warn1 = Instance.new("IntValue", Player)
    local Warn2 = Instance.new("StringValue", Player)
    Warn1.Name = "WarnCount"
    Warn2.Name = "WarnReason"
end)
1 Like

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