Basically I want this code to work for next 3 seconds (like if OnServerEvent then there gonna be 3 seconds for touch event to fire, or else you will need to OnServerEvent again)
Here is the code
local rs = game:GetService("ReplicatedStorage")
local rockamount = 1
local function takeDamage(player, tool, hum, torso, char, anotherchar)
hum:TakeDamage(tool:GetAttribute("damage"))
local facepart = anotherchar:FindFirstChild("FacePart")
local knockback = Instance.new("BodyVelocity")
knockback.Velocity = facepart.CFrame.LookVector * tool:GetAttribute("power")
knockback.P = 5000
knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
knockback.Parent = torso
game:GetService("Debris"):AddItem(knockback, .1)
end
local touched
local hitboxconnect
hitboxconnect = rs.hitboxevent.OnServerEvent:Connect(function(player, tool)
touched = tool.Hitbox.Touched:Connect(function(hit)
if tool:GetAttribute("cooldown") == false and hit.Parent.Humanoid and hit.Parent.Torso and hit.Parent.Humanoid.Health > 0 and hit.Parent.Name ~= player.Name and CanHit then
touched:Disconnect()
local char = hit:FindFirstAncestorWhichIsA("Model")
local anotherchar = player.Character or player.CharacterAdded:Wait()
local rockcoins = player.leaderstats.rockcoins
local hum = char.Humanoid
local torso = char.Torso
tool.Hitbox.CanCollide = true
tool:SetAttribute("cooldown", true)
rockcoins.Value += rockamount
takeDamage(player, tool, hum, torso, char, anotherchar)
task.wait(tool:GetAttribute("speed"))
tool.Hitbox.CanCollide = false
tool:SetAttribute("cooldown", false)
else
touched:Disconnect()
end
end)
end)
I tried to remake script listening to you but it completely broke, why?
local rs = game:GetService("ReplicatedStorage")
local rockamount = 1
local function takeDamage(player, tool, hum, torso, char, anotherchar)
hum:TakeDamage(tool:GetAttribute("damage"))
local facepart = anotherchar:FindFirstChild("FacePart")
local knockback = Instance.new("BodyVelocity")
knockback.Velocity = facepart.CFrame.LookVector * tool:GetAttribute("power")
knockback.P = 5000
knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
knockback.Parent = torso
game:GetService("Debris"):AddItem(knockback, .1)
end
local function cooldownFunction(tool)
for i = 0,3 do
task.wait(1)
tool:SetAttribute("cooldown", 3)
end
end
local touched
local hitboxconnect
hitboxconnect = rs.hitboxevent.OnServerEvent:Connect(function(player, tool)
cooldownFunction(tool)
touched = tool.Hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Torso") and hit.Parent:FindFirstChild("Humanoid").Health > 0 and hit.Parent.Name ~= player.Name then
if tool:GetAttribute("cooldown") ~= 3 then
touched:Disconnect()
local char = hit:FindFirstAncestorWhichIsA("Model")
local anotherchar = player.Character or player.CharacterAdded:Wait()
local rockcoins = player.leaderstats.rockcoins
local hum = char.Humanoid
local torso = char.Torso
tool.Hitbox.CanCollide = true
tool:SetAttribute("cooldown", true)
rockcoins.Value += rockamount
takeDamage(player, tool, hum, torso, char, anotherchar)
task.wait(tool:GetAttribute("speed"))
tool.Hitbox.CanCollide = false
tool:SetAttribute("cooldown", false)
end
else
touched:Disconnect()
end
end)
end)
Also again sorry for sending in couple of hours, I played again