Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My sword won't inflict damage to others?

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)

3 comments

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.

0

Well, not just mobile. On all platforms.

0

That didn't solve my problem, thanks though.

2 answers

✓ Accepted answer

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))

2 comments

0

Oh wow, your script worked! Thanks a lot!

0

your welcome

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

2 comments

0

First Line*

0

That didn't work, thanks tho

This discussion is preserved as it was. New answers, comments, and votes are closed.