Need help putting a delay on this taser

  1. What do you want to achieve? I want there to be a cooldown reload for the taser

  2. What is the issue? There’s no delay for the reload for this taser

  1. What solutions have you tried so far? Tried editing the TimeVal but the clicking R 2x overrides it.

ServerScriptServices

Tazer Server
game.ReplicatedStorage.TazerEvents:WaitForChild("event1").OnServerEvent:connect(function(plr,mtarg,Tool)
	local v = (mtarg - Tool.Cart.Position).unit
	local v2 = ((mtarg + Vector3.new(0,-1.5,0)) - Tool.Cart.Position).unit
	
	local spawnPos = Tool.Cart.Position
	spawnPos  = spawnPos + (v * 2)
	
	local barb_1 = Instance.new("Part")
	
	barb_1.Position = spawnPos
	barb_1.FormFactor = 3
	barb_1.Size = Vector3.new(1,1,1)
	barb_1.Velocity = v * 500--1000
	barb_1.BrickColor = BrickColor.new(194)
	barb_1.BottomSurface = 0
	barb_1.TopSurface = 0
	barb_1.Name = "TaserBarb"
	barb_1.Elasticity = 0
	barb_1.Reflectance = 0.1
	barb_1.Friction = 1
	
	Tool.BarbMesh:clone().Parent = barb_1
	
	local sc = script.BarbScript:clone()
	sc.Parent = barb_1
	sc.Disabled = false
	
	local force = Instance.new("BodyForce")
	force.force = Vector3.new(0,150,0)
	force.Parent = barb_1
		
	barb_1.Parent = game.Workspace
	
	local barb_2 = barb_1:clone()
	barb_2.Position = spawnPos + (v2 * 2) + Vector3.new(0,-0.5,0)
	barb_2.Velocity = v2 * 500
	barb_2.BodyForce.force = Vector3.new(0,150,0)
	barb_2.Parent = game.Workspace
	
	Tool.BlastDoor1.Transparency = 1
	Tool.BlastDoor2.Transparency = 1
	
	
	
	local function BarbTouched(hit,barb)
		if hit == nil then return end
		if hit.Parent == nil then return end
		if hit.Parent:findFirstChild("Humanoid") or hit.Parent:findFirstChild("Zombie") ~= nil then
		if hit.Parent.Name == plr.Name then return end
		
		
		if hit.Parent:FindFirstChild("OverrideScript") == nil then
			local s = script.OverrideScript:clone()
			s.Parent = hit.Parent
			game.ReplicatedStorage.TazerEvents:WaitForChild("event1"):FireClient(plr,hit.Parent)
			s.Disabled = false
		end
		
		barb:Remove()
		
		elseif hit.CanCollide == true then
			barb:Remove()
		end
	end
	
	barb_1.Touched:connect(function(hit) 
		--game.ReplicatedStorage.event1:FireClient(plr,"BarbTouched",hit,barb_1) 
		BarbTouched(hit,barb_1)
	end)
	barb_2.Touched:connect(function(hit) 
		--game.ReplicatedStorage.event1:FireClient(plr,"BarbTouched",hit,barb_2) 
		BarbTouched(hit,barb_2)
	end)
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event2").OnServerEvent:connect(function(plr,target)
	target:WaitForChild("OverrideScript"):Destroy()
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event3").OnServerEvent:connect(function(plr,target)
	local st = script.OverrideScript:clone()
	st.Disabled = false
	st.Parent = target
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event4").OnServerEvent:connect(function(plr,hit)
	if hit.Parent:findFirstChild("Humanoid") or hit.Parent:findFirstChild("Zombie") ~= nil then
		local s = script.DriveStunScript:clone()
		s.Parent = hit.Parent
		s.Disabled = false
	end
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event5").OnServerEvent:connect(function(plr,Tool)
	local electrictextures = {"http://www.roblox.com/asset/?id=109201383", "http://www.roblox.com/asset/?id=109201366", "http://www.roblox.com/asset/?id=109201474", "http://www.roblox.com/asset/?id=109201980", "http://www.roblox.com/asset/?id=109202011"}
	local function GetElectricTexture()
		local r = math.random(1,#electrictextures)
		return electrictextures[r]
	end
	Tool.Electric.Decal.Texture = GetElectricTexture()	
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("keybindevent").OnServerEvent:connect(function(plr,key,Tool)
	if key == "y" then
		if Tool.Lamp.Light.Enabled == true then
			Tool.Lamp.Light.Enabled = false
		else
			Tool.Lamp.Light.Enabled = true
		end
	end
	
	if key == "r1" then
		Tool.Cart.Transparency = 1
		Tool.Cart.CanCollide = false
		Tool.BlastDoor1.Transparency = 1
		Tool.BlastDoor1.CanCollide = false
		Tool.BlastDoor2.Transparency = 1
		Tool.BlastDoor2.CanCollide = false
	end
	
	if key == "r2" then
		Tool.Cart.Transparency = 0
		Tool.Cart.CanCollide = true
		Tool.BlastDoor1.Transparency = 0
		Tool.BlastDoor1.CanCollide = true
		Tool.BlastDoor2.Transparency = 0
		Tool.BlastDoor2.CanCollide = true
	end
end)

Script inside the taser

Taser LocalScript
game.ReplicatedStorage.TazerEvents:WaitForChild("event1").OnServerEvent:connect(function(plr,mtarg,Tool)
	local v = (mtarg - Tool.Cart.Position).unit
	local v2 = ((mtarg + Vector3.new(0,-1.5,0)) - Tool.Cart.Position).unit
	
	local spawnPos = Tool.Cart.Position
	spawnPos  = spawnPos + (v * 2)
	
	local barb_1 = Instance.new("Part")
	
	barb_1.Position = spawnPos
	barb_1.FormFactor = 3
	barb_1.Size = Vector3.new(1,1,1)
	barb_1.Velocity = v * 500--1000
	barb_1.BrickColor = BrickColor.new(194)
	barb_1.BottomSurface = 0
	barb_1.TopSurface = 0
	barb_1.Name = "TaserBarb"
	barb_1.Elasticity = 0
	barb_1.Reflectance = 0.1
	barb_1.Friction = 1
	
	Tool.BarbMesh:clone().Parent = barb_1
	
	local sc = script.BarbScript:clone()
	sc.Parent = barb_1
	sc.Disabled = false
	
	local force = Instance.new("BodyForce")
	force.force = Vector3.new(0,150,0)
	force.Parent = barb_1
		
	barb_1.Parent = game.Workspace
	
	local barb_2 = barb_1:clone()
	barb_2.Position = spawnPos + (v2 * 2) + Vector3.new(0,-0.5,0)
	barb_2.Velocity = v2 * 500
	barb_2.BodyForce.force = Vector3.new(0,150,0)
	barb_2.Parent = game.Workspace
	
	Tool.BlastDoor1.Transparency = 1
	Tool.BlastDoor2.Transparency = 1
	
	
	
	local function BarbTouched(hit,barb)
		if hit == nil then return end
		if hit.Parent == nil then return end
		if hit.Parent:findFirstChild("Humanoid") or hit.Parent:findFirstChild("Zombie") ~= nil then
		if hit.Parent.Name == plr.Name then return end
		
		
		if hit.Parent:FindFirstChild("OverrideScript") == nil then
			local s = script.OverrideScript:clone()
			s.Parent = hit.Parent
			game.ReplicatedStorage.TazerEvents:WaitForChild("event1"):FireClient(plr,hit.Parent)
			s.Disabled = false
		end
		
		barb:Remove()
		
		elseif hit.CanCollide == true then
			barb:Remove()
		end
	end
	
	barb_1.Touched:connect(function(hit) 
		--game.ReplicatedStorage.event1:FireClient(plr,"BarbTouched",hit,barb_1) 
		BarbTouched(hit,barb_1)
	end)
	barb_2.Touched:connect(function(hit) 
		--game.ReplicatedStorage.event1:FireClient(plr,"BarbTouched",hit,barb_2) 
		BarbTouched(hit,barb_2)
	end)
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event2").OnServerEvent:connect(function(plr,target)
	target:WaitForChild("OverrideScript"):Destroy()
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event3").OnServerEvent:connect(function(plr,target)
	local st = script.OverrideScript:clone()
	st.Disabled = false
	st.Parent = target
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event4").OnServerEvent:connect(function(plr,hit)
	if hit.Parent:findFirstChild("Humanoid") or hit.Parent:findFirstChild("Zombie") ~= nil then
		local s = script.DriveStunScript:clone()
		s.Parent = hit.Parent
		s.Disabled = false
	end
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("event5").OnServerEvent:connect(function(plr,Tool)
	local electrictextures = {"http://www.roblox.com/asset/?id=109201383", "http://www.roblox.com/asset/?id=109201366", "http://www.roblox.com/asset/?id=109201474", "http://www.roblox.com/asset/?id=109201980", "http://www.roblox.com/asset/?id=109202011"}
	local function GetElectricTexture()
		local r = math.random(1,#electrictextures)
		return electrictextures[r]
	end
	Tool.Electric.Decal.Texture = GetElectricTexture()	
end)

game.ReplicatedStorage.TazerEvents:WaitForChild("keybindevent").OnServerEvent:connect(function(plr,key,Tool)
	if key == "y" then
		if Tool.Lamp.Light.Enabled == true then
			Tool.Lamp.Light.Enabled = false
		else
			Tool.Lamp.Light.Enabled = true
		end
	end
	
	wait(2)
	
	if key == "r1" then
		wait(5)
		Tool.Cart.Transparency = 1
		Tool.Cart.CanCollide = false
		wait(0.1)
		Tool.BlastDoor1.Transparency = 1
		Tool.BlastDoor1.CanCollide = false
		wait(0.1)
		Tool.BlastDoor2.Transparency = 1
		Tool.BlastDoor2.CanCollide = false
		wait(0.1)
	end
	
	wait (3)
	
	if key == "r2" then
		Tool.Cart.Transparency = 0
		Tool.Cart.CanCollide = true
		wait(0.1)
		Tool.BlastDoor1.Transparency = 0
		Tool.BlastDoor1.CanCollide = true
		wait(0.1)
		Tool.BlastDoor2.Transparency = 0
		Tool.BlastDoor2.CanCollide = true
		wait(0.1)
	end
end)
2 Likes

use your usual old debounce method, wrap everything in a debounce so nothings overwrite everytime, make sure you make the debounce check on the server so exploiters cant abuse spam

3 Likes

I’m not really experience in scripting so do you have a good video on how I would do that or good article I could read up on? Also thank you for your assistance!

1 Like

I saw that but how do incorporated into the script, since it’s not a touchpart.

I don’t know the line of code where the reload is, but essentially add a debounce when a player reloads.

1 Like

It doesn’t matter that its using a Touch, its just the example given.
You could also do this with a GUI button, where you don’t want players to spam it like crazy.
Example:

local GUI = script.Parent
local Button = GUI.ImageButton

local Debounce = 1

Button.MouseButton1Click:Connect(function()
    if Debounce == 1 then --if the Debounce is default then
        Debounce = 2 --right after that 'if' set Debounce to not be default
        --make the button do its job
        wait(1) --this would be how long the debounce is 
        Debounce = 1 --return Debounce to its original value
    end
end)

You are basically telling the script that it cannot be repeated again until Debounce has been set back to 1. You could also use true and false instead of 1 and 2, but I prefer numbers.

1 Like