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

Sword Only Kills Player On Client?

Asked by 4 years ago
Edited 4 years ago

I have a server script with this code:

local candamage = true
script.Parent.Activated:Connect(function()
    script.Parent.Blade.Touched:Connect(function(hit)
        local Char = hit:FindFirstAncestorOfClass("Model")
            if Char then
            local Hum = Char:FindFirstChild("Humanoid")
                   if hum then
         if candamage == true then
                    candamage = false
                    Hum:TakeDamage(15)
                    wait(0.6)
                    candamage = true
             end
     end
        end
    end)
end)

But it only kills the player on the client like its inside a local script

1 answer

Log in to vote
0
Answered by
Farsalis 369 Moderation Voter
4 years ago

Try this

local SP = script.Parent
local debounce = true
local damage = 20
SP.Activated:Connect(function()
    SP.Touched:Connect(function(hit)
        local EnemyHumanoid = hit.Parent:WaitForChild("Humanoid", 3)
        if EnemyHumanoid and debounce then
            debounce = false
            EnemyHumanoid:TakeDamage(damage)    
            wait(0.5)
            debounce = true
        end
    end)
end)
0
it worked a little but then the same bug happend UnforgivenJr3087 26 — 4y
0
Hm, weird i tested it out on a local server. Worked for client and server. How are you testing it? Farsalis 369 — 4y
0
have a friend join the place itself UnforgivenJr3087 26 — 4y
0
and the output says "Touched is not a valid member of Tool" UnforgivenJr3087 26 — 4y
View all comments (6 more)
0
Ok, so do this. Hav everything but the damage part. Try a Remote Event, that when fired by a local script, the server sciprt in SSS, find the player and damage them. Farsalis 369 — 4y
0
nvm fixed it UnforgivenJr3087 26 — 4y
0
how'd you fix? Farsalis 369 — 4y
0
sorry i just set the touch as the blade and it was fixed UnforgivenJr3087 26 — 4y
0
can you specify? Just want to edit the code correctly. Farsalis 369 — 4y
0
Sp.Blade.Touched:Connect(function(hit) i set the touch detector to that line UnforgivenJr3087 26 — 4y
Ad

Answer this question