https://web.roblox.com/library/5872123105/Please-fix-this-script
So there's leaderstats where every 2 seconds the player gets 100 'minutes' (i'm just testing with it) which works. There's a keycard that the player gets after 300 'minutes' of the leaderstats. (which works.) But when the player resets/dies the item is removed from the inventory (backpack) which I don't want, I want the gear to STAY within the inventory. And the player can't get the item back because it's already been over '300' so I need help with that... Sorry if this sounds confusing, I can explain more sort of.
Well, it looks like you are giving the Keycard to the player, when the player join and then breaking the loop when the requirements are met. There is a CharacterAdded
event, which fires on character respawn :
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) repeat wait() until char -- Waits until full character is loaded -- The code end) end)
So, to simplify your code, you can make it a function and execute it on character respawn.
function GiveKeycard(plr) local KeyCard = game.ServerStorage["KeyCard"] while wait(1) do if plr:WaitForChild("leaderstats"):FindFirstChild("Minutes").Value >= 300 then KeyCard:Clone().Parent = plr:WaitForChild("Backpack") break end end end
Now, you can fire the function on PlayerRespawn :
function GiveKeycard(plr) local KeyCard = game.ServerStorage["KeyCard"] while wait(1) do if plr:WaitForChild("leaderstats"):FindFirstChild("Minutes").Value >= 300 then KeyCard:Clone().Parent = plr:WaitForChild("Backpack") break end end end game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) repeat wait() until char -- Waits until full character is loaded GiveKeyCard(player) end) end)
Lemme know if it helps!