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

My sword won't inflict damage to others?

Asked by
Jxdenx 45
5 years ago

I think it's a problem with my RemoteEvent script, I'm not really sure but here are the scripts.

LocalScript:

local tool = script.Parent

tool.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
       tool.Kill:FireServer()
            end)
    end)

Script:

script.Parent.Kill.OnServerEvent:Connect(function()
    script.Parent.union.Touched:Connect(function(hit)
        if script.Parent.CanDamage.Value == true and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Creator") == nil then
        local bloodarea = {"UpperTorso", "LowerTorso", "Head"}
        local bloodface = {"Top", "Bottom", "Front", "Back", "Left", "Right"}
        local chosenarea = bloodarea[math.random(1,#bloodarea)]
        local chosenface = bloodface[math.random(1,#bloodface)]
        local blood = game.ReplicatedStorage.Blood:Clone()
        local creator = Instance.new("IntValue")
        creator.Name = "Creator"
        creator.Parent = script.Parent.Parent
        blood.EmissionDirection = chosenface
        blood.Parent = hit.Parent[chosenarea]
        script.Parent.CanDamage.Value = false
        hit.Parent.Humanoid:TakeDamage(100)
    end
    end)
end)
0
Use connect; Connect is deprecated. Also, if you want your sword to work with mobile as well, you should probably use tool.Activated on line 4 of the LocalScript. lunatic5 409 — 5y
0
Well, not just mobile. On all platforms. lunatic5 409 — 5y
0
That didn't solve my problem, thanks though. Jxdenx 45 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I know making a new script is unefficient but I don't know how to script that well and what you are doing above is kind of hard to read. I honestly think it is a lot less challenging to use this script than to use an event. Make sure if you use my script that it is in a server script located under your sword's handle. It has a debounce if you don't want it to immeadiately kill someone it won't. This script might seem stupid but I hope it helps you.

-- DominusInfinitus

function debounce(func)  --Debounce optional 
    local isRunning = false    
    return function(...)       
        if not isRunning then
            isRunning = true

            func(...)          

            isRunning = false
        end
    end
end

local Activater = script.Parent.Parent
local damagePack = script.Parent
local damageAmount = 0 
local function OnActivated() --sets damage later so you wont get hurt
      damageAmount = -25 -- change value if you would like
end


Activater.Activated:Connect(OnActivated) 


local function OnUnEquipped() --If it isUnequipable but if not get rid of this part
      damageAmount = 0
end


UnEquipper.Unequipped:Connect(OnUnEquipped)


  local function Ouch(otherPart) --Once you are holding sword touched event wont play for you
    local character = otherPart.Parent --defines character
    local humanoid = character:FindFirstChild("Humanoid")  --defines humanoid
    if humanoid then 
        local currentHealth = humanoid.Health
        local newHealth = currentHealth + damageAmount --add or subtract health.
        humanoid.Health = newHealth
    end
end


    damagePack.Touched:Connect(debounce(Ouch))
0
Oh wow, your script worked! Thanks a lot! Jxdenx 45 — 5y
0
your welcome RetroGalacticGamer 331 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I don't think You added this at the beginning of both the localScript and Script

-- I am assuming "Kill" is the RemoteEvent and it should be in ReplicatedStorage
local RepStorage = game:GetService('ReplicatedStorage')
local Kill = RepStorage.Kill
-- Put this in first place
0
First Line* RichCookieGamer 7 — 5y
0
That didn't work, thanks tho Jxdenx 45 — 5y

Answer this question