Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I need my script fixed BACKPACK 'data?'

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.

4 comments

0

Put the script here

0

local KeyCard = game.ServerStorage["KeyCard"] game.Players.PlayerAdded:Connect(function(plr) while wait(1) do if plr:WaitForChild("leaderstats"):FindFirstChild("Minutes").Value >= 300 then KeyCard:Clone().Parent = plr:WaitForChild("Backpack") break end end end)

0

The script, keycard is in the model link

0

You may require a backpack saver

1 answer

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.