DebounceTime problem

Hello, I have a script that allows a player to push another player, everything works fine, the only problem and the “DebounceTime” it allows not to spam the E key for 3 seconds, it works, but when I join the game, i need to press E at least ten times before i can push the player…but that’s not what I want…

Basically, I want to be able to push the player directly, and only after having the 3 second cooldown.

I don’t know if this is clear, sorry about that!

to better understand:

robloxapp-20220905-0027358.wmv (1.9 MB)

here is the ModuleScript which is in ServerScriptService:

local sound = workspace.Sound

local module = {}

local DebriService = game:GetService('Debris')


local TKPushData = {
	DebounceTime = 3,
	Debounce = {},
	Victims = {},
}


function CheckDebounce(Character,Target)
	local CanAttackVictim = true 
	local CanAttack = false 
	
	if not TKPushData['Debounce'][Character] then 
		TKPushData['Debounce'][Character] = {
			Last = tick()+TKPushData['DebounceTime']
		}
		CanAttack = true 
	end
	
	if TKPushData['Debounce'][Character] then 
		if tick() - TKPushData['Debounce'][Character]['Last'] >= TKPushData['DebounceTime'] then 
			CanAttack = true 
		else 
			CanAttack = false 
		end
	end
	
	if  TKPushData[table.find(TKPushData['Victims'],Target)] then
		CanAttackVictim = false
	end
	
	if CanAttack==true and CanAttackVictim==true then 
		return true 
	end
		
		--Targets[table.find(Targets, Target)]

end

module.TelekineticPush = function(Character,Target,CameraVector)
	local HRP = Character.HumanoidRootPart 
	
	local THRP = Target.HumanoidRootPart 
	local TRagdoll = Target.Ragdoll
	
	if CheckDebounce(Character,Target) == true then 
		TKPushData['Debounce'][Character] = {Last = tick()}
		local Force = Instance.new('LinearVelocity')
		TRagdoll.Value += 1
		local Force = Instance.new("BodyVelocity")
		Force.MaxForce = Vector3.new(700,math.huge,700)
		Force.P = math.huge
		Force.Velocity = Vector3.new(45,0,45) *CameraVector
		Force.Velocity += Vector3.new(0,10,0)
		Force.Parent = THRP 
		DebriService:AddItem(Force,.3)
		
		
		local Animation = Instance.new('Animation')
		Animation.AnimationId = 'rbxassetid://'
		local Track = Character.Humanoid.Animator:LoadAnimation(Animation)
		Track:Play()
		sound:Play()

		
		
		
		wait(TKPushData['DebounceTime'])
		for _, v in pairs(TKPushData['Victims']) do 
			if v == Target then 
				table.remove(TKPushData['Victims'],v)
			end
		end
	end
	
	
	
end







return module

Try this and tell me if it works:

local sound = workspace.Sound

local module = {}

local DebriService = game:GetService('Debris')


local TKPushData = {
	DebounceTime = 3,
	Debounce = {},
	Victims = {},
}


function CheckDebounce(Character,Target)
	local CanAttackVictim = true 
	local CanAttack = false 
	
	if not TKPushData['Debounce'][Character] then 
		TKPushData['Debounce'][Character] = {
			Last = tick()
		}

		CanAttack = true 
	else
		if tick() - TKPushData['Debounce'][Character]['Last] >= TKPushData.DebounceTime then
			CanAttack = true

			TKPushData['Debounce'][Character]['Last] = tick()
			table.clear(TKPushData['Victims'])
		end
	end
	
	return CanAttack
		
		--Targets[table.find(Targets, Target)]

end

module.TelekineticPush = function(Character,Target,CameraVector)
	local HRP = Character.HumanoidRootPart 
	
	local THRP = Target.HumanoidRootPart 
	local TRagdoll = Target.Ragdoll
	
	if CheckDebounce(Character,Target) == true then 
		local Force = Instance.new('LinearVelocity')
		TRagdoll.Value += 1
		local Force = Instance.new("BodyVelocity")
		Force.MaxForce = Vector3.new(700,math.huge,700)
		Force.P = math.huge
		Force.Velocity = Vector3.new(45,0,45) *CameraVector
		Force.Velocity += Vector3.new(0,10,0)
		Force.Parent = THRP 
		DebriService:AddItem(Force,.3)
		
		
		local Animation = Instance.new('Animation')
		Animation.AnimationId = 'rbxassetid://'
		local Track = Character.Humanoid.Animator:LoadAnimation(Animation)
		Track:Play()
		sound:Play()
	end
	
	
	
end

there is an error in the writing it is underlined in red “malformed string”, “incomplete statement” ect…
1fa796bd340eb0fd1f2be618ade96971

Here’s a fix to their script, Don’t know if it will work I just fixed the issue

ok i see, but it doesn’t work anyway :face_with_diagonal_mouth:

Still no solution ? Can someone help me :persevere:

I think that this is the problem in your function. It is not that you have to spam “E” 10 times before it works, it’s that your function is putting a 3 second debounce on any new player introduced to the debounce table. Then,

if TKPushData['Debounce'][Character] then 
		if tick() - TKPushData['Debounce'][Character]['Last'] >= TKPushData['DebounceTime'] then 
			CanAttack = true 
		else 
			CanAttack = false 
		end
	end

this code evaluates as CanAttack = false.

1 Like

Oh yes, and how can i fix this?

Oh, thank you ! by erasing “CanAttack = false” it worked ! :smiley: