Hi. I’m making bomber tag game like minecraft tnt tag.
I want to make if player has bomb and that player touches other player, bomb is passed.
But it doesn’t work.
Please tell me if you think you have a solution.
(“bombertag” is module script function)
bombertag.PickUp()
task.spawn(function()
while true do
task.wait(0.1)
for _, v in pairs(players:GetPlayers()) do
v.Character:FindFirstChild("HumanoidRootPart").Touched:Connect(function(hit)
if hit.Parent ~= v.Character and hit.Parent:FindFirstChildOfClass("Humanoid") then
if v.Character:FindFirstChild("Bomb") and not hit.Parent:FindFirstChild("Bomb") then
print("Aww")
bombertag.GiveBomb(hit.Parent)
bombertag.RemoveBomb(v.Character)
end
end
end)
end
end
end)
task.spawn(function()
local elapsed = 0
while true do
for i = 30, 0, -1 do
elapsed = i
print(elapsed)
task.wait(.1)
end
for _, v in pairs(players:GetPlayers()) do
if v.Character and v.Character:FindFirstChild("Bomb") then
bombertag.Explosion(v.Character)
end
end
task.wait(5)
bombertag.PickUp()
end
end)
Use workspace:GetPartsInPart() to detect if the player is touching another player’s character parts, then use the data to pass the bomb to another player.
I think it works with both CanCollide and non-CanCollide objects as it just detects if parts are touching or inside of eachother. Another function does the same, but I’m pretty sure it isn’t as reliable as GetPartsInPart.
I watched how to use :GetPartsInPart() after reply, I moved pick up function and want to define player as pickedplr, but an error like the following screenshot occurs.
I don’t understand why such a message appears even though there is an else.
local pickedplr
task.wait(5)
local function PickUp()
pickedplr = players:GetPlayers()[math.random(1, #players:GetPlayers())]
bombertag.GiveBomb(pickedplr.Character)
return pickedplr
end
PickUp()
task.spawn(function()
while true do
task.wait(0.1)
for _, v in pairs(workspace:GetPartsInPart(pickedplr.Character.Torso)) do
if pickedplr:FindFirstChildOfClass("Humanoid") then
if v.Parent ~= pickedplr and v.Parent:FindFirstChildOfClass("Humanoid") then
if pickedplr:FindFirstChild("Bomb") and not v.Parent:FindFirstChild("Bomb") then
print("Aww")
bombertag.GiveBomb(v.Parent)
bombertag.RemoveBomb(pickedplr)
pickedplr = v.Parent
end
end
else
if v.Parent ~= pickedplr.Character and v.Parent:FindFirstChildOfClass("Humanoid") then
if pickedplr.Character:FindFirstChild("Bomb") and not v.Parent:FindFirstChild("Bomb") then
print("Aww")
bombertag.GiveBomb(v.Parent)
bombertag.RemoveBomb(pickedplr.Character)
pickedplr = v.Parent
end
end
end
end
end
end)
Pretty bad to constantly making a Instance and setting it up everytime someone touches it, it’s best to actually just pass the Object to the other player inventory.