Pass the bomb help (done)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

A working Pass The Bomb game

  1. What is the issue? Include screenshots / videos if possible!

The script works but after one pass, the bomb cannot be passed again

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried every solution I could but none helped

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

My script is disabled but is enabled in a round system

local debounce = false

local player = workspace.CurrentlyPlaying:GetChildren()[math.random(1, #workspace.CurrentlyPlaying:GetChildren())]

local currentplayer = player

local bomb = game.ReplicatedStorage.Maps["Pass The Bomb"].Bomb:Clone()
bomb.Parent = player --bomb is a BillboardGUI

for _, v in pairs(workspace.CurrentlyPlaying:GetChildren()) do
v.Humanoid.JumpPower = 0
end

task.spawn(function()
while wait(10) do
local explosion = Instance.new("Explosion", workspace)
explosion.DestroyJointRadiusPercent = 0
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.Position = currentplayer.Torso.Position
currentplayer.Humanoid.Health = 0
wait(1)
explosion:Destroy()
end
end)

currentplayer.Torso.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
currentplayer = hit.Parent
bomb.Parent = currentplayer
wait(0.5)
debounce = false
end
end
end)

workspace:FindFirstChild("CurrentMap").Destroying:Connect(function()
bomb:Destroy()
end)

repeat wait() until #workspace.CurrentlyPlaying:GetChildren() == 1

game.ReplicatedStorage.Values.EndGame.Value = true

Video and console:

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes
A nitpicky thing first (ignore if you want)

Why do you define a player and then set the currentplayer to the player, the “player” variable seems pointless.

The issue here is that you only define the touched event once. This means that only the first player would detect it. Instead, you should do something like this:

local curEvent

local function bombChange(hit)
 if hit and hit.Parent:FindFirstChild("Humanoid") then
  if debounce == false then
   debouce = true
   currentplayer = hit.Parent
   bomb.Parent = currentplayer
   curEvent:Disconnect()
   curEvent = currentplayer.Torso.Touched:Connect(bombChange)
   wait(0.5)
   debounce = false
  end
 end
end)

curEvent = currentplayer.Torso.Touched:Connect(bombChange)

note that as I havn’t used studios in nearly 2 months, have no access to google, and cant test with studios rn, there might be some issues like syntax stuff in that code

3 Likes

I’ll try this, thanks!
btw I was going to remove the player variable but forgot to lol

2 Likes

nope, is that an error happening or just something you noticed? (since by the way the script runs, curEvent should be connected before bombChange can ever happen, so curEvent should always be defined)

oh lol

1 Like

im stupid, forget what i said lol

ill test the code now

It works! Thank you so much! I’ve been trying to fix this problem for like 4 days lol

(im going to study connections now)

edit: literally after 5 minutes I fully understand connections now

@PANDASonNOOB how would I make the bomb go to someone new when the currentplayer dies

Check if the player died by using some sort of connection on the currentplayer as well, and then change the currentplayer, the bomb.Parent, and disconnect all previous events.

I still have no access to google rn, so I do not know what specific function to use, but healthChanged on the humanoid (or whatever its called) or humanoid.Died are 2 possibly good choices. (Make sure they work on the server and doesn’t only work locally)

1 Like

I’ll be sure to try this! thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.