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.
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
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
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