Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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.

0
Is the name of the iten "Tool"? Necro_las 412 — 4y

1 answer

Log in to vote
1
Answered by
pwx 1581 Moderation Voter
4 years ago
Edited 4 years ago

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)
Ad

Answer this question