Childadded event not working

so im making a anticheat script inside of a folder that holds all the exploiters names

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Ban = require(ReplicatedStorage.ModuleScripts.Commands.Ban)
local AntiCheatStrikes = ServerStorage.PlayerList.AntiCheatStrikes

AntiCheatStrikes.ChildAdded:Connect(function(v)
	print("value added")
	if v:IsA("IntValue") then
		local exploiter = v.Name

		v:GetPropertyChangedSignal("Value"):Connect(function()
			print(v.Value)
			if v.Value >= 20 then
				local Banned = Players:FindFirstChild(exploiter).UserId

				Ban.Function(Banned,"Banned for exploiting")
			end
		end)
	end
end)

the problem is when i add a new value something is suppose to print but it dosnt

this is how the value is created and changed

HungerTimer.Count:Connect(function(timeelapsed)
		local currenttime = math.floor(timeelapsed + 0.5)
		
		if currenttime == 15 then
			print("timer ended resetting..")
			HungerTimer:Reset()
			HungerTimer:Start()
			
			if AntiCheatStrikes:FindFirstChild(player.Name) then
				local Strike = AntiCheatStrikes[player.Name]
				Strike.Value += 1
			else
				local Strike = Instance.new("IntValue")
				Strike.Name = player.Name
				Strike.Value = 1
				Strike.Parent = AntiCheatStrikes
			end
		end
	end)
1 Like

Are there any errors that are occurring? Also, does the strike already exist within the folder?

1 Like

no errors. The strike gets cloned into the folder if a timer ends

1 Like

Show me your Start() function. It may be yielding.

1 Like

the function is apart of a module that i got from a plugin

function Timer:Start() -- Begins a timer
	self.StartTime = tick()
	self.LastStep = self.StartTime
	self.Countdown = runS.Heartbeat:Connect(function()
		local currentTime = tick()-self.StartTime
		if self.CountStep then
			if tick()-self.LastStep >= self.CountStep then
				self.CountEvent:Fire(currentTime) -- return current time
				self.LastStep = self.LastStep+self.CountStep
			end
		end
		if currentTime >= self.Duration then
			-- fire event, cancel timer
			self.IsRunning = false
			self.CompletedEvent:Fire(currentTime)
			self:Stop()
		end
	end)
end

it works most of the time

Does this print? I’m trying to figure out what prints and doesn’t prints.

yeah that prints but not

print("value added") ```

Add print statements here and tell me if both statements work.

if AntiCheatStrikes:FindFirstChild(player.Name) then
				print("strike increased")
				local Strike = AntiCheatStrikes[player.Name]
				Strike.Value += 1
			else
				print("strike added")
				local Strike = Instance.new("IntValue")
				Strike.Name = player.Name
				Strike.Value = 1
				Strike.Parent = AntiCheatStrikes
			end

image

whole hunger script

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local HungerDrain = ReplicatedStorage.RemoteEvents.HungerDrain
local TimerModule = require(ReplicatedStorage.ModuleScripts.Timer)
local AntiCheatStrikes = ServerStorage.PlayerList.AntiCheatStrikes

Players.PlayerAdded:Connect(function(player) -- real hunger system
	local HungerTimer = TimerModule.new(16)
	
	player.CharacterAdded:Connect(function(character)
		HungerTimer:Start()
		
		local hunger = player:WaitForChild("NonPvPStats").Hunger
		local Human = character.Humanoid

		while true do
			wait(12.5)
			if hunger.Value > 0 then
				hunger.Value = hunger.Value - 3
			elseif hunger.Value == 0 then
				hunger.Value = 0
				Human.Health = Human.Health - 10
			end
		end
	end)
	
	HungerDrain.OnServerEvent:Connect(function(player,value) -- fake hungers system
		HungerTimer:Reset()
		HungerTimer:Start()
		
		if value ~= 3 then
			if AntiCheatStrikes:FindFirstChild(player.Name) then
				local Strike = AntiCheatStrikes[player.Name]
				Strike.Value += 1
			else
				local Strike = Instance.new("IntValue")
				Strike.Name = player.Name
				Strike.Value = 1
				Strike.Parent = AntiCheatStrikes
			end
		else 
			return -- innocent
		end
	end)
	
	HungerTimer.Count:Connect(function(timeelapsed)
		local currenttime = math.floor(timeelapsed + 0.5)
		
		if currenttime == 15 then
			print("timer ended resetting..")
			HungerTimer:Reset()
			HungerTimer:Start()
			
			if AntiCheatStrikes:FindFirstChild(player.Name) then
				print("strike increased")
				local Strike = AntiCheatStrikes[player.Name]
				Strike.Value += 1
			else
				print("strike added")
				local Strike = Instance.new("IntValue")
				Strike.Name = player.Name
				Strike.Value = 1
				Strike.Parent = AntiCheatStrikes
			end
		end
	end)

end)

Where’s the childadded script?

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Ban = require(ReplicatedStorage.ModuleScripts.Commands.Ban)
local AntiCheatStrikes = ServerStorage.PlayerList.AntiCheatStrikes

AntiCheatStrikes.ChildAdded:Connect(function(v)
	print("value added")
	if v:IsA("IntValue") then
		local exploiter = v.Name

		v:GetPropertyChangedSignal("Value"):Connect(function()
			print(v.Value)
			if v.Value >= 20 then
				local Banned = Players:FindFirstChild(exploiter).UserId

				Ban.Function(Banned,"Banned for exploiting")
			end
		end)
	end
end)

Can I ask what is .Count? Do you have a module script associated with this?

when a timer starts this event fires every second and i rounded the number

Alright I can’t determine why it isn’t firing so I’m going to ask this, is the intvalue creation in a local script?

nah its in a server script but a remote event fires every 12 secs from a local script to check if the local script isnt deleted

i figuired out the problem it was pretty simple lol
so scripts dont run if they are under server storage
so all i had to do was move my script from that to serverscriptservice :man_facepalming:
image
image
image

2 Likes