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

Can someone help me make a cooldown on my blaster pistol?

So, i made a laser blaster and its kinds unbalanced because it doesnt has cooldown. so, i asked other people how and they said no, i tryed it myself but it failed. can you help me? the code:~~~~~~~~~~~~~~~~~ local tool = script.Parent local sound = tool:WaitForChild("Gunfire") local player = game:GetService("Players").LocalPlayer

tool.Equipped:connect(function(mouse) print("Tool equipped!")

if script.Parent.Canshoot then

mouse.Button1Down:connect(function()
	print("Mouse pressed!")
	local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
	local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
	script.Parent.Shooting.Value = true

	local beam = Instance.new("Part", workspace)
	beam.BrickColor = BrickColor.new("Really red")
	beam.FormFactor = "Custom"
	beam.Material = "Neon"
	beam.Transparency = 0.5
	beam.Anchored = true
	beam.Locked = true
	beam.CanCollide = false

	local distance = (tool.Gun.CFrame.p - position).magnitude
	beam.Size = Vector3.new(0.3, 0.3, distance)
	beam.CFrame = CFrame.new(tool.Gun.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

	game:GetService("Debris"):AddItem(beam, 0.1)
					
	if script.Parent.Shooting.value then
						script.Parent.Gunfire:Play()
						script.Parent.Gun.PointLight.Enabled=true
						wait(0.1)
						script.Parent.Gun.PointLight.Enabled=false


	if part then
		local humanoid = part.Parent:FindFirstChild("Humanoid")

		if not humanoid then
			humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
		end

		if humanoid then
			humanoid:TakeDamage(22)
				
				
			end
			
		end
	end
end)

end)


2 answers

Like this

mouse.Button1Down:connect(function()
	if script.Parent.Canshoot.Value == true then
		script.Parent.Canshoot.Value = false
		--script
		wait(HowMuchToWait)
		script.Parent.Canshoot.Value = true
	end
end)

5 comments

0

Fixed

0

Hi, i did it but at the end) it says : expected identifier, got )

0

this is the code, again

0

its thge other ansewer VVVV

0

i missed some script thats why

  local tool = script.Parent
local sound = tool:WaitForChild("Gunfire")
local player = game:GetService("Players").LocalPlayer
 
tool.Equipped:connect(function(mouse)
	print("Tool equipped!")
 
	mouse.Button1Down:connect(function()
		print("Mouse pressed!")
		local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
		script.Parent.Shooting.Value = true
 
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("Really red")
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.5
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
 
		local distance = (tool.Gun.CFrame.p - position).magnitude
		beam.Size = Vector3.new(0.3, 0.3, distance)
		beam.CFrame = CFrame.new(tool.Gun.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
 
		game:GetService("Debris"):AddItem(beam, 0.1)
						
		if script.Parent.Shooting.value then
							script.Parent.Gunfire:Play()
							script.Parent.Gun.PointLight.Enabled=true
							wait(0.1)
							script.Parent.Gun.PointLight.Enabled=false

 
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
 
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
 
			if humanoid then
				humanoid:TakeDamage(22)
					
					
				end
				
			end
		end
	end)
end)

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