Well you don’t need this while loop because you put the tool in backpack from server.
So to fire an event when player leaves server i writed you this
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterRemoving:Connect(function(char)
-- THIS WILL BE FIRED WHEN PLAYER WILL LEAVE
end)
end)
local plr = game.Players.LocalPlayer
game.ReplicatedStorage.RemoteEvent1.OnClientEvent:Connect(function()
while true do
print("a")
local PaperTool = game.ReplicatedFirst:FindFirstChild("Paper"..(plr.SecretFolder.Paper.Value+1)):Clone()
PaperTool.Parent = plr.Backpack
print("ab")
if plr.Backpack:FindFirstChild("Paper"..tostring(plr.SecretFolder.Paper.Value+1)) then
print("break loop")
break
end
end
end)
For some reason it prints “break loop” despite still not having the tool stored in my inventory