[SOLVED!] PlayerRemoving function doesn't always work

I’ve been trying to make something but seems like if the players stays too much in the game the functions doesn’t work.

Note: There’s a script adds value to the IntValue.


game.Players.PlayerRemoving:Connect(function(Player)
	local grouprank = Player:GetRankInGroup(5847534)
	
	if Whitelist[tostring(grouprank)] then
		local sendhook = httpservice:JSONEncode({
			['content'] = "",
			['embeds'] = {{
				['title'] = Player.Name,
				['url'] = 'https://www.roblox.com/users/'..Player.UserId..'/profile',
				['thumbnail'] = {
					['url'] = 'https://www.roblox.com/headshot-thumbnail/image?userId='..Player.UserId..'&width=420&height=420&format=png',
				},
				['fields'] = {
					{
						['name'] = 'Has achieved the time of: ',
						['value'] = Player.Time.Value..' Minutes'
					}
				},
			}}
		})
		httpservice:PostAsync(webhook, sendhook)
	end
end)

image

Now if I stay for much longer in the game the function won’t even fire, even tried printing the value and nothing.

image

Now here’s the value 60 seconds after.

After staying much longer in the game the webhook didn’t fire.

If there’s someone that knows how to fix this issue I’d be very thankful!

1 Like

Add print statements to see if its even running. Based off the code you’ve shown this is probably something else going on in your game.

2 Likes

Nope it did not print after I stayed 60 seconds inside the game.

1 Like

So you’re saying it will print inside the function if they are in the game for less than 60 seconds?

2 Likes

image

Seems like so.

1 Like

Then something is deleting the script to prevent it from functioning or unique behaviour. CTRL SHIFT + F and check for anything that is :Delete() :Remove() GetFenv or require() and see if anything isnt something isn’t intended/right. If this isn’t the problem then you will need to provide more information as there is nothing at all wrong with your code, if nothings being deleted/removed then its possible your whitelist is constantly changing?

2 Likes
local Whitelist = {
	["255"] = true,
	['254'] = true,
	['252'] = true
}

local httpservice = game:GetService('HttpService')
local webhook = 'o'

game.Players.PlayerAdded:Connect(function(Player)
	local grouprank = Player:GetRankInGroup(5847534)
	
	if Whitelist[tostring(grouprank)] then
		local New_Value = Instance.new("IntValue",Player)
		New_Value.Name = "Time"
	end
end)
while wait(1) do
	for Index, Player in pairs(game.Players:GetPlayers()) do
		if Player:FindFirstChild("Time") then
			Player.Time.Value = Player.Time.Value + 1
		end
	end
end

I don’t know there is a whitelist system as showed in the code, but I don’t think that’s the problem.

1 Like

probably not going to solve the problem but i feel like if you just wrap that white loop in a spawn(function() your problem will go away, im presuming your playerremoving function is right below that while loop and since its constantly looping itll never connect the playerremoving functional the signal. Again if what you said is true about it working before 60 seconds then this isn’t the problem. I recommend checking all the code in your game and if it’s still not working then recode it in a empty baseplate using api guidance + devforum

2 Likes

Alright thank you, and you’re right I have re-written the code and this time it printed, so the issue may be the whitelist system or the webhook.

local Players = game.Players

Players.PlayerAdded:Connect(function(player)
	local NewValue = Instance.new('IntValue', player)
	NewValue.Name = 'Player_Time'
end)

Players.PlayerRemoving:Connect(function(player)
	print(player.Player_Time.Value)
end)

while true do
	wait(60)
	for Index, Player in pairs(game.Players:GetPlayers()) do
		if Player:FindFirstChild("Player_Time") then
			Player.Player_Time.Value = Player.Player_Time.Value + 1
		end
	end
end
1 Like