Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would i limit bomb dropping in this script?

alrighty mctighty so in im trying to get this script to fire the event based off of the SD value like if it is set to 2 they can drop 2 "bombs in within a 5 second timeframe and after that timeframe is up they can place another 2 in that 5 second timeframe.... ok i cant really explain this off the top of my head but like in Bomberman when you pick up a "bombup" you can drop 1 more bomb than you could have before but you have to wait until the first one that you dropped has exploded and the way i have my bombs set up is the event triggers and creates the bomb and beeps 3 times then explodes which all happens in exactly 5 seconds.. if you can understand what im trying to say here then props to you

the game im working on is here https://www.roblox.com/games/2706427178/Pre-Alpha-God-Of-Bombs if you want to mess around with how i already got things set up

localscript:

local UIS = game:GetService("UserInputService")
local FocusedTextBox = UIS:GetFocusedTextBox()
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local RootPart = character.HumanoidRootPart
local Spot = RootPart.Position
local BombDropped = false
local SD = player.SnoopDogg
UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Gamepad1 then
		if input.KeyCode == Enum.KeyCode.F or input.KeyCode == Enum.KeyCode.ButtonX then
			if UIS:GetFocusedTextBox() == nil then
				if not BombDropped then
					BombDropped = true
--					for i=SD.Value, 10, 0.5 do   -- use for gamemodes	
--					    print(i)
--				for i = 1, SD.value, 0.5 do
					game.ReplicatedStorage.DropBomb:FireServer(Spot,RootPart)
					wait(5)
--					end
					BombDropped = false
				end
			end
		end
	end
end)

1 comment

0

I think i understand what you meant and made something up, let me know if i misunderstood.

1 answer

✓ Accepted answer

Ok so just spitballing here, I don't know if it'll work or not. The only concern I have is whether or not the bomb dropping part will continue to work while the while loop is running. If not you could I guess make the MaxBombs/Bombs variables save into the player and reset the Bombs value in a different script?

local UIS = game:GetService("UserInputService")
local FocusedTextBox = UIS:GetFocusedTextBox()
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local RootPart = character.HumanoidRootPart
local Spot = RootPart.Position
local BombDropped = false
local SD = player.SnoopDogg
local MaxBombs = 2
local Bombs = 0

UIS.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Gamepad1 then
        if input.KeyCode == Enum.KeyCode.F or input.KeyCode == Enum.KeyCode.ButtonX then
            if UIS:GetFocusedTextBox() == nil then
                if Bombs.Value < MaxBombs.Value then
                    Bombs.Value = Bombs.Value + 1
                    game.ReplicatedStorage.DropBomb:FireServer(Spot,RootPart)
                end
            end
        end
    end
end)

while wait(5) do
	Bombs.Value = 0
end

5 comments

0

yep that works out the only issue is it places 3 but thats easy to fix and and once the first bomb goes off it stll lets you place 3 after but idk sounds easy to fix

0

Oh im dumb, ill fix it.

0

It should've been < not <= on line 17, so when at 2 it would still accept the input and drop the bomb. Im just glad it worked, usually freehand stuff in the editor doesnt go well lol.

0

Now it should allow 2 bombs to be dropped every 5 seconds, numbers are easily adjustable. Like i said you could also put that maxbomb value into the player and the player could "upgrade" to raise it. Seems like a cool idea.

0

alright thank you i appreciate that

This discussion is preserved as it was. New answers, comments, and votes are closed.