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

Why does my sword deal deal damage when testing in studio mode, but not in a server?

Asked by 7 years ago

I've made a sword and I have this weird problem were it will do damage to a humanoid when testing my place in studio, but when I start up a server it will only deal damage once and then it stops. Is there some kind of client side v.s server side thing going on? Please Help, thank you.

Damage code located in the Blade of the model:

wait(0.01)
CanDamage = true
plr = game.Players.LocalPlayer

script.Parent.Touched:connect(function(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    if hum then
            if CanDamage == true and script.Parent.Parent.Swinging.Value == true then
                CanDamage = false
                hum:TakeDamage(10)
                plr.swordlvl.Value = plr.swordlvl.Value + 2
                wait(0.8)
                CanDamage = true
            end
        end

end)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You wrote the script Inefficiently, and I can see why

wait(0.01)
CanDamage = true
plr = game.Players.LocalPlayer

script.Parent.Touched:connect(function(hum) -- Changed "part" to "hum"
    -- local hum = part.Parent:FindFirstChild("Humanoid") Delete this
    if hum and hum.Parent:FindFirstChild("Humanoid") then -- "hum" is the Player who touched the part/Sword.
            if CanDamage == true and script.Parent.Parent.Swinging.Value == true then
                CanDamage = false
                hum.Parent.Humanoid:TakeDamage(10) -- I forgot to add the "Parent.Humanoid" part after "hum"
                plr.swordlvl.Value = plr.swordlvl.Value + 2
                wait(0.8)
                CanDamage = true
            end
        end

end)

0
Thank you for responding, I replaced the code with what you edited and got an error: "TakeDamage is not a valid member of Part", I'm not sure what is happening...is it not detecting the humanoid? roblox99456789 104 — 7y
0
I fixed my mistake, It should work now GeezuzFusion 200 — 7y
0
Good news, the sword does damage again. Bad news, I'm back to the same problem I had before. When I play in studio mode it does damage, but when I open a server and play it only does damage once and then stops...I don't even know what to do anymore, I've tried multiple tests and it still won't work...thanks for trying to help. roblox99456789 104 — 7y
0
Problem Fixed!! Moved all the code to a local script and it worked!! So glad I can finally continue working on my game roblox99456789 104 — 7y
Ad

Answer this question