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

How do you kill a player until a certain item is in their inventory?

I'm trying to create a script that kills me until I have an item in my inventory. (a script gives one item to a player everytime they respawn) This is currently my code

repeat	
	local tool = game.Players.leoultrapultra2.Backpack:FindFirstChild("Tool")
	if tool == nil then
		game.Players.leoultrapultra2.Character.Humanoid.Health = 0
	end
until tool == true

I don't understand how I am supposed to check if the player has the item or not. I'm trying to use findfirstchild but I'm not sure how to use this either.

1 comment

0

Is the name of the iten "Tool"?

1 answer

Rather than a repeat loop, use CharacterAdded it's way more efficient.

-- [[ SERVICES ]] --

Players = game:GetService('Players')

-- [[ MAIN SCRIPT ]] --

function onCharacterAdded(Player, Character)
	local Tool = Player.Backpack:FindFirstChild('toolName')
	if Tool then
		Character:BreakJoints()
	end
	local Tool = Character:FindFirstChild('toolName')
	if Tool then
		Character:BreakJoints()
	end
end

function onPlayerAdded(Player)
	Player.CharacterAdded:Connect(Character)
		onCharacterAdded(Player, Character)
	end)
end

-- [[ CONNECTIONS ]] --

Player.PlayerAdded:Connect(onPlayerAdded)

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