You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want to make cooldown so it doesnt damage or knockback too fast
- What is the issue? Include screenshots / videos if possible!
It simply doesnt work, I can spam click to insta kill the character
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried checking if im using right instances or making the cooldown set to true only in touched event, but nothing changed
Here’s the script
local rs = game:GetService("ReplicatedStorage")
local rockamount = 1
local function takeDamage(hum, torso, player, damage, power)
hum:TakeDamage(damage)
local char = player.Character or player.CharacterAdded:Wait()
local facepart = char:FindFirstChild("FacePart")
local knockback = Instance.new("BodyVelocity")
knockback.Velocity = facepart.CFrame.LookVector * power
knockback.P = 5000
knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
knockback.Parent = torso
task.wait(0.1)
knockback:Destroy()
end
local function ontouched(player, power, damage, speed, hitbox, cooldown)
cooldown.Value = true
hitbox.CanCollide = true
local touchedConn = hitbox.Touched:Connect(function(part)
for i, currentplayer in pairs(game.Players:GetPlayers()) do
if part.Parent.Name == currentplayer.Name and cooldown.Value == false then
cooldown.Value = true
local rockcoins = player.leaderstats.rockcoins
rockcoins.Value = rockcoins.Value + rockamount
local hum = part.Parent:FindFirstChild("Humanoid")
local torso = part.Parent:FindFirstChild("Torso")
if hum and torso and hum.Health > 0 then
takeDamage(hum, torso, player, damage, power)
end
end
end
task.wait(speed)
hitbox.CanCollide = false
cooldown.Value = false
end)
touchedConn:Disconnect()
end
rs.hitboxevent.OnServerEvent:Connect(ontouched)
Also here’s the another script where the rock’s parent doesnt get set to parent
Server script:
local rs = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(plr)
local rock = Instance.new("StringValue")
rock.Name = "rock"
rock.Value = "default"
rock.Parent = plr:WaitForChild("leaderstats")
end)
local changeconn = nil
task.spawn(function()
while task.wait() do
for _, player in pairs(game.Players:GetPlayers()) do
local rock = player:WaitForChild("leaderstats").rock
local therock = rock.Name.." rock"
rock.Changed:Connect(function()
for _, currentrock in pairs(game.ServerStorage.rocks:GetChildren()) do
if currentrock.Name == therock then
local char = player.Character or player.CharacterAdded:Wait()
for _, delete in pairs(char:GetChildren()) do
if delete.Name ~= therock and delete:IsA("Tool") then
delete:Destroy()
end
end
for _, delete2 in pairs(player.Backpack:GetChildren()) do
if delete2.Name ~= therock and delete2:IsA("Tool") then
delete2:Destroy()
end
end
for _, delete3 in pairs(game.StarterPack:GetChildren()) do
if delete3.Name ~= therock and delete3:IsA("Tool") then
delete3:Destroy()
end
end
local clonedtool = currentrock:Clone()
clonedtool.Parent = player.Backpack
local clonedtool2 = currentrock:Clone()
rs.starterpack2:FireClient(player, clonedtool2)
end
end
end)
end
end
end)
for i, v in pairs(workspace.spawn.stands:GetChildren()) do
-- spawns
v:FindFirstChild("ClickDetector").MouseClick:Connect(function(plr)
-- clickdetector event
if v:GetAttribute("price") <= plr:FindFirstChild("leaderstats").rockcoins.Value then
-- if price smaller than rockcoins amount
plr:FindFirstChild("leaderstats").rock.Value = v.Name
for _, tool in pairs(game.ServerStorage.rocks:GetChildren()) do
--all items in game
if v:GetAttribute("rock") == tool.Name then
-- if item name is the same
for _, starterpack in pairs(game.StarterPack:GetChildren()) do
--starterpack item
starterpack:Destroy()
end
for _, deletetool in pairs(plr.Backpack:GetChildren()) do
for _, startergui in pairs(game.StarterGui:GetChildren()) do
startergui:Destroy()
end
-- tool that needs to be deleted
if deletetool:IsA("Tool") then
--if tool is in backpack
deletetool:Destroy()
else
for _, thedeletetool in pairs(plr.Character:GetChildren()) do
--if tool is in character
if deletetool:IsA("Tool") then
deletetool:Destroy()
end
end
end
end
local backpack = plr.Character or plr.Backpack
local backpackprob = plr.Backpack
local clonedtool = tool:Clone()
local anotherclonedtool = tool:Clone()
clonedtool.Parent = plr.Backpack
rs.starterpack2:FireClient(plr, anotherclonedtool)
end
end
end
end)
end
and local scripts
local rs = game:GetService("ReplicatedStorage")
rs.starterpack.OnClientEvent:Connect(function(tool)
tool.Parent = game.StarterPack
end)
local rs = game:GetService("ReplicatedStorage")
rs.starterpack2.OnClientEvent:Connect(function(tool)
tool.Parent = game.StarterPack
end)
Thanks.