I’m making a server script where kill points pile up when I get hit by a bomb, but I’m not looking for Humanoid I’m trying to get, I’m only looking for player’s backpack value.
Help me with what’s wrong with this
touched = Bomb.Touched:connect(function(part)
if part:IsDescendantOf(Tool.Parent) then return end
if contains(Knives, part) then return end
local e = Instance.new('Explosion',workspace)
e.Position = Bomb.Position
Bomb["Explosions 9 (SFX)"]:Play()
local w = Instance.new("Weld")
w.Part0 = part
w.Part1 = knife
w.C0 = part.CFrame:toObjectSpace(knife.CFrame)
w.Parent = w.Part0
if part:FindFirstChild('Humanoid').Health <= 0 then
getPlayer().leaderstats.BOMB.Value += 1
end
touched:disconnect()
end)
Bomb.Touched:connect(function(part)
The part refers to the otherPart touching the bomb such as leg or arm etc, which are all descendants of the Character Model. if part:FindFirstChild('Humanoid').Health <= 0 then
The humanoid is also a child of the Character model. So the part will never have the humanoid as a child.
Try instead looking for the part’s parent, like this: if part.Parent:FindFirstChild("Humanoid").Health <= 0 then
Could you please further explain what you are trying to achieve? From what I can understand, it seems you are struggling to get the player who touched the bomb. If that is the main problem, here is an example of how you can get the player:
if part.Parent:FindFirstChild("Humanoid") then -- checks if humanoid exists within the character
local character = part.Parent -- creates a variable of the character
local player = game.Players:GetPlayerFromCharacter(character) -- gets the player
if player then -- makes sure the player exists
-- execute code
end
end