Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't i make this move have a cooldown(i'm using a bool value and a local script)?

So i have a move which fires with an animation and works perfectly,the only problem is i can't manage to put an cooldown on it.Here's the script:

local cf = script.CanFire
cf = true

-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
local disappear = .6 
local damage = 50 
local key = 'q' 
local speed = 500 
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
plr = script.Parent.Parent.Parent
chr = plr.Character
hum = chr.Humanoid

if cf == true then

Player = game.Players.LocalPlayer 
Character = Player.Character 
Mouse = Player:GetMouse() 
function onKeyDown(keyx) 
	if keyx == key:lower() then 
		local ffa = hum:LoadAnimation(script.FFA)
		ffa:Play()
		wait(1)
		local x = Instance.new("Part") 
		x.TopSurface = "Smooth" 
		x.BottomSurface = "Smooth" 
		x.Shape = "Ball" 
		x.Transparency = 1
		x.Size = game.ReplicatedStorage.x1.Size
		game.Debris:AddItem(x, disappear)
		x.BrickColor = BrickColor.new("Bright red") 
		local f = Instance.new("ParticleEmitter")
		f.Parent = x
		f.Texture =  "rbxassetid://410256160"
		f.Rate = 300
		f.Size = game.ReplicatedStorage.Meraf.Size
		
		
		
		local y = Instance.new("BodyVelocity") 
		y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
		y.velocity = Character.Torso.CFrame.lookVector*speed
		y.Parent = x  
		x.Parent = workspace 
		x.CFrame = Character.Torso.CFrame*CFrame.new(0, 0, -12)
		x.Touched:connect(function(Part)
			if Part.Parent:findFirstChild("Humanoid") and Part.Parent.Name ~= Player.Name then
				Part.Parent.Humanoid:TakeDamage(damage)
				x:Destroy()
				cf = false
				wait(3)
				cf = true
			end
		end)
	end 
end 
Mouse.KeyDown:connect(onKeyDown)
end

2 comments

0

you need to use cf.Value to set cf's value.

0

i did that but it still didn't work

1 answer

✓ Accepted answer

Lots of errors in your scripts.

First, In line 2, you changed line 1 from an object to a boolean. So Say cf.Value = true on line 2.

Next, In your “onKeyDown” function you have lots of errors. I won’t even list them. Learn coding. So do more research.

Then, Mouse.KeyDown is deprecated. So switch to ContextActionService or UserInputService.

Finally, You didn’t make the "f" in findFirstChild an uppercase. Not findFirstChild You should Take case sensitivity into consideration. If you can’t spell, don’t even script.

local canFire = script.CanFire
canFire.Value = true

local disappear = 0.5
local dmg = 50
local key = Enum.KeyCode.Q
local speed = 500

local plr = game:GetService('Players').LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

function fire() 
    local ffa = char.Humanoid:LoadAnimation(script.FFA)
    ffa:Play()
    wait(1)
    local x = Instance.new("Part",game.Workspace")
    x.TopSurface = Enum.SurfaceType.Smooth
    x.BottomSurface = Enum.SurfaceType.Smooth
    x.Shape = Enum.PartType.Ball
    x.Transparency = .5
    x.Size = game:GetService("ReplicatedStorage").x1.Size
    x.BrickColor = BrickColor.new"Bright red"
    
    local f = Instance.new("ParticleEmitter", x)
    f.Texture = "rbxassetid://410256160"
    f.Rate = 300
    f.Size = game:GetService("ReplicatedStorage").Meraf.Size
    
    local y = Instance.new("BodyVelocity", x)
    y.Velocity = Vector3.new(char.Torso.CFrame.lookVector * speed)
    y.MaxForce = Vector3.new( math.huge, math.huge, math.huge )
    x.CFrame = char.Torso.CFrame * CFrame.new(0, 0, -12)
    
    local dmgScript = script.DmgScript:Clone() — I will make the dmgscript later. Make sure it’s Disabled property is set to true
    dmgScript.Parent = x
    dmgScript.Disabled = false
end

game:GetService("ContextActionService"):BindAction(“Fire”, fire, false, key)

Now for the dmgScript. Yes they must be different scripts. Make sure its Disabled property is set to true. The above script will set it to false so it can work.

local cf = script.Parent.CanFire — this script is inside the localscript 

script.Parent.Touched:Connect(function(part)
    local hum = part.Parent:FindFirstChild("Humanoid")

    if hum then
        hum:TakeDamage(50)
        
        wait(1) 
        script.Parent:Destroy()
        cf.Value = false
        wait(3)
        cf.Value = true
    end
end)

1 comment

0

Everything works except the dmg script,i did disable it

This discussion is preserved as it was. New answers, comments, and votes are closed.