I made a damage script but It won't damage the test dummy.
local debounce = true local candamage = script.Parent:WaitForChild("Blade").Damage.CanDamage.Value script.Parent.Activated:Connect(function() if debounce == true then debounce = false local player = game.Players.LocalPlayer candamage = true local Anim = player.Character.Humanoid:LoadAnimation(script.Animation) Anim:Play() wait(2) debounce = true candamage = false end end)
There is no error message, I don't know why the dummy's health won't go down. Here's the script in the blade:
script.Parent.Touched:Connect(function(hit) if script.CanDamage == true then if hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid:TakeDamage(15) end end end)
Is something wrong with my script?
So, I'm pretty sure the problem is that at the top of your code, you're saying
local candamage = script.Parent:WaitForChild("Blade").Damage.CanDamage.Value
The problem with that is it's going to make the game think you just want the value of that object, and not the object its self. That means when you try to change the variable, it's just going to change it locally in the script and not in the acutal bool value. At the top when your refrencing it, don't use .Value so you can change the actual object, instead of that value just in the one script. I hope that made sense to you, here's an example of how it would go.
local debounce = true local candamage = script.Parent:WaitForChild("Blade").Damage.CanDamage script.Parent.Activated:Connect(function() if debounce == true then debounce = false local player = game.Players.LocalPlayer candamage.Value = true local Anim = player.Character.Humanoid:LoadAnimation(script.Animation) Anim:Play() wait(2) debounce = true candamage.Value = false end end)
Oh, and I just noticed one more additional problem as well, in the second script, you wrote if script.CanDamage == true, instead of if script.CanDamage.Value == true.
If this worked for you, please mark it as finished. If you have problems with this, please write a responce, and I can help you further.
:)
You need to use remote events in this case. Sorry if this doesn't help
local ReplicatedStorage = game:GetService("ReplicatedStorage") local CanAttack = ReplicatedStorage:WaitForChild("CanAttack") --when you need to change your value CanAttack:FireServer(value)
local ReplicatedStorage = game:GetService("ReplicatedStorage") local CanAttack = Instance.new("RemoteEvent", ReplicatedStorage) CanAttack.Name = "CanAttack" local function CanAttack(player, value) -- Client automatically adds player in player.Blade.Damage.CanDamage = value -- something like that end