so this function won’t work when I have the variables and stuff it is a script to find if the player has a tool if it doesn’t then it should kill him here is the script:
local player = game.Players.LocalPlayer
local Key = game.Workspace.Key
local function key()
if player.Backpack.Key then
player.Humanoid.Health = 1
else
player.Humanoid.Health = 0
end
end
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Backpack = player:WaitForChild("Backpack")
local Humanoid = Character:WaitForChild("Humanoid")
local Key = game.Workspace.Key
local function key()
if Backpack:FindFirstChild("Key") then
Humanoid.Health = 1
else
Humanoid.Health = 0
end
end
wait(60)
key()
Couple things as well:
Is this a LocalScript or a Server Script? Server Scripts aren’t handle to detect the LocalPlayer
The Player and Character are 2 different things, the Player would be the current player that’s in the game, and the Character is actually the Character Model that spawns in your game
If you want to search for a specific thing, use FindFirstChild which will check if that specific name is inside the Player’s Backpack or not once 60 seconds pass
So, what actually happens is that when you actually equip a tool, it’s actually reparented to your Character’s Model so it actually leaves the Backpack
To fix that, add another conditional check if the Tool is either in the Backpack, or in the Character Model:
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Backpack = player:WaitForChild("Backpack")
local Humanoid = Character:WaitForChild("Humanoid")
local Key = game.Workspace.Key
local function key()
if Backpack:FindFirstChild("Key") or Character:FindFirstChild("Key") then
Humanoid.Health = 1
else
Humanoid.Health = 0
end
end
wait(60)
key()
It still just takes away my health even when I have the tool in my character or backpack and it doesn’t kill me it just takes my health to 0 and I somehow am alive from that.