i need if If player have any weapons then he died else print(“player haven’t weapons”)
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)
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()’.
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)
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
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.