If player have any weapons

i need if If player have any weapons then he died else print(“player haven’t weapons”)
image

Part = script.Parent 
local debounce = false
------------------------------------
modelname="Prisoners" -- Put the EXACT name of the team here
------------------------------------

function onTouched(hit) 
	local human = hit.Parent:FindFirstChild("Humanoid") 
	local name = hit.Parent.Name
	local weapon = false

	local player = game.Players:FindFirstChild(name)
	
	if (human ~= nil ) then
		if game.Players:playerFromCharacter(hit.Parent).TeamColor==game.Teams:FindFirstChild(modelname).TeamColor then
			if debounce == false then
				debounce = true
				local character = player.Character
				human.Health = 0
				wait(5)
				debounce = false
			end
		end	
	end
end
		

			
	
 
connection = Part.Touched:connect(onTouched)
1 Like

What you need to do is fire an event when the player dies. Then, bind this event to a function that checks if the player’s backpack contains any tools by using ‘:FindFirstChild()’.

1 Like

Make the player variable to this;
local player = game:GetPlayerFromCharacter(hit.Parent)
Here

1 Like

Add a .Died event onto the Player’s humanoid, then see if there are any tools in their backpack. It’s simple

can you make it in script pls? Idk how to do it

local debounce = false

local modelName = "Prisoners"

function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

        if humanoid ~= nil then
            if plr.TeamColor == game.Teams:FindFirstChild(modelName).TeamColor then
                if debounce == false then
                    debounce = true
                    local char = plr.Character or plr.CharacterAdded:Wait()
                    humanoid.Health = 0
                    wait(5)
                    debounce = false
                end
            end
        end
    end
end

connection = part.Touched:Connect(onTouched)

Hopefully works.

Can’t you make it check if the player has a tool in his backpack via #player.Backpack:GetChildren() or in his character via character:FindFirstChildOfClass("Tool")?

I can tell this is a free model from the use of deprecated methods, so I’ll teach you better methods

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local part = script.Parent 
local debounce = false

------------------------------------
modelname="Prisoners" -- Put the EXACT name of the team here
------------------------------------

function onTouched(hit) 
	local character = hit.Parent
	local human = character:FindFirstChildOfClass("Humanoid") 

	local player = Players:GetPlayerFromCharacter(character)
	
	if not human or not player or player.TeamColor ~= Teams[modelname].TeamColor or debounce then 
		return
	end
	if #player.Backpack:GetChildren() > 0 or character:FindFirstChildOfClass("Tool") then
		debounce = true	
		human.Health = 0
		wait(5)
		debounce = false
	else
		print("No")
	end
end
 
part.Touched:Connect(onTouched)

You don’t need connection and weapon variables since you don’t do anything relating to disconnection and you never used it respectively

Use game:GetService(Service) instead of game.Service to ensure you get the service

A guard clause removes unneeded indentation, which is good in your case since you had 3 indentations for 3 if statements.

There’s a lot of deprecated methods when it’s recommended to use the newer functions

The Part variable was unlocalized which was a bit inconsistent

I recommend you grasp a bit of knowledge of Luau so you are able to do what you need without a free model

2 Likes

It’s a very simple example. And as Embat already said that you don’t need the connection variable is true because really there isn’t anything to do with disconnecting or anything.

It isn’t works. Idk why . a d32

I think it’s cause of my typo

local player = Players:GetPlayerFromCharacrer(character)

Should be

local player = Players:GetPlayerFromCharacter(character)