Hi, I have a script that checks if a player has the right item. If the player does not have the right item he dies. But somehow after even trying many ways scripting it, it only kills me or doesnt kill me, with item or without item. What I mean by that is that somehow when the player has the item he dies and when he does not have the item he dies too. But I need the player to stay alive when having the item.
local BaggagesColors = {"BlackBaggage","BlueBaggage","BrownBaggage","DarkblueBaggage","GrayBaggage","GreenBaggage","OrangeBaggage","PinkBaggage","RedBaggage","VioletBaggage","WhiteBaggage","YellowBaggage"}
local function checkIfPlayerHasBaggage()
for i,v in pairs(game.Players:GetPlayers()) do
if table.find(BaggagesColors, v.Backpack) then
doNothing()
else
if not table.find(BaggagesColors, v.Backpack) then
v.Character.Humanoid.Health = 0
end
end
end
end
sry I am not very good in scripting and I really tried many diffrent ways to change the script. Like: else v.character.humanoid.Health = 0 and other ways
does anyone got an idea to fix this?
instead of checking for all players in the game check for each player put a local script inside the player’s character (if you want other players to see you dying use RemoteEvent)
for i,v in pairs(script.Parent:GetChildren()) do
if table.find(BaggagesColors, v.Name) then – Note this gonna only work when the player equip the tool
– do nothing
else
local hum = v:FindFirstChild(“Humanoid”)
if hum then
hum.Health = 0
end
end)
1 Like
well I will assume the post owner want player who don’t have item die when something happen I may can help if you show us the explorer of inventory/backpack
1 Like
theres a timer and when it runs out and the player does not have the tool in his backpack he dies. The timer and the other stuff works but only this killing script does not work correctly
Is your backpack look like this?

1 Like
it looks like this and its in workspace

oh and I should mention that this script is a command which I can just type below a timerevent like this:
its a script in ServerScriptService

1 Like
But you’re not checking if the player has a baggage but if the table contains a player’s backpack which is a folder.
The first if statement is useless and you can remove it leaving only the second one
1 Like
I have rewrite it abit basically it pick name from BaggagesColors table and check if it have item with that name in inventory
local BaggagesColors = {"BlackBaggage","BlueBaggage","BrownBaggage","DarkblueBaggage","GrayBaggage","GreenBaggage","OrangeBaggage","PinkBaggage","RedBaggage","VioletBaggage","WhiteBaggage","YellowBaggage"}
local function checkIfPlayerHasBaggage()
for i,v in pairs(game.Players:GetPlayers()) do
local Baggages = v.Backpack.Baggages
local Haveitem = false
for _, color in pairs(BaggagesColors) do
if Baggages:FindFirstChild(color) then
Haveitem = true
end
end
if not Haveitem then
v.Character.Humanoid.Health = 0
end
end
end
If i get the backpack order correctly that it
1 Like
it seems to work but the item goes to the character when selecting it but I can fix it myself. Thanks for the help