im trying to make a sword.
Script :
readykill = true ready = true activated = false local function OnTouch(other) if activated and readykill then local human = other.Parent:FindFirstChild("Humanoid") if not human then return end if human.Parent == Tool then return end human:TakeDamage(script.Parent.dmg.Value) readykill = false wait(script.Parent.Delay.Value) readykill = true else print("not ready") end end
Output: image.png
change activated to true, or check if activated is false, as you are checking if activated is true, however it is false, this means the script is just passing that statement, then due to human not existing due to that if statement not running, it will go to the end.
to fix it just make activated false, or check if "activated == false" , or use "not activated"
readykill = true ready = true activated = false script.Parent.Activated:Connect(function() if readykill == true and activated == false then print("attack") readykill = false activated = true wait(5) readykill = true activated = false else if readykill == false and activated == true then print("not attack") end end end)
you forgot to add "==" and true or false, it should be like this "if readykill == true and activated == false then" and after the main code for example damage to the player and then write in the same function so that the script turns off readykill and active turns on "readykill = false activated = true" then add "wait(for example 0.6)" and set readykill and active as they were "readykill = true activated = false" then write else if readykill == false and activated == true then print("not worked") -- for example and don't forget ends and sorry for my english I used google translator
You can use loops to do a certain thing everytime a value is false or true. Like this:
local isReadyToSlash = false wait(cooldown) isReadyToSlash = true wait(cooldown) while wait() and isReadyToSlash == true do blahblahblah:FireServer() print(tostring(isReadyToSlash)) end
You left your "activated" variable to false, making the sword not work. Since I have no clue how you set up your sword, you have to edit some stuff in the code provided, especially the "-- Edit this." ones.
The Tool object has an "Activated" event to which you could connect your function.
Also, your sword's Handle (wherever it may be) has a Touched event. Your "OnTouch" function must be connected to it.
I added an extra function that listens to the Sword's Activated event, with a 1-second wait (you may change the function to however you want, as long as the "activated" variable is enabled then disabled.)
readykill = true ready = true activated = false local Tool = script.Parent -- Edit this. Where did you place your handle? local function Activate() if not activated then activated = true -- Activates the sword. wait(1) -- idk how long do you want the sword to be activated? activated = false end end local function OnTouch(other) if activated and readykill then local human = other.Parent:FindFirstChild("Humanoid") if not human then return end if human.Parent == Tool then return end human:TakeDamage(script.Parent.dmg.Value) readykill = false wait(script.Parent.Delay.Value) readykill = true else print("not ready") end end Tool.Touched:Connect(OnTouch) script.Parent.Parent.Activated:Connect(Activate) -- Edit this. I don't know where your Tool object is in the Explorer.
Let me know if there are problems with my solution.