Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I was making a damage script and now It wont work??

Asked by 4 years ago
Edited 4 years ago

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?

0
The problem is that you're changing the value in a LocalScript, so it only changes for the client, not the Server. So the server reads the value as false, but the client reads it as true. killerbrenden 1537 — 4y
0
To fix this, you'll have to use RemoteEvents to send arguments/messages to the server to tell them you want this action to be crossed. killerbrenden 1537 — 4y
0
oh KamKam_AJHasBeenBan 37 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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.

:)

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You need to use remote events in this case. Sorry if this doesn't help

Client

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CanAttack = ReplicatedStorage:WaitForChild("CanAttack")
--when you need to change your value
CanAttack:FireServer(value)

Server

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

Answer this question