Need some help with a knife damage script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Whenever the blade touches another player’s character it damages them

  2. What is the issue? Include screenshots / videos if possible!
    It doesn’t do any damage.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried changing some stuff and looked on the devforum but i cant find it

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

image

Serverside script

local tool = script.Parent

local function damage(oPart)
	if oPart.Parent:FindFirstChild("Humanoid") then
		local ownerChar = tool.Parent
		local ownerPlr = game:GetService("Players"):GetPlayerFromCharacter(ownerChar)
		
		
		if oPart:FindFirstChild("Humanoid") and oPart:FindFirstChild("Humanoid").Parent ~= ownerChar then
			local hum = oPart:FindFirstChild("Humanoid")
			local oPlr = game:GetService("Players"):GetPlayerFromCharacter(hum.Parent)
			if oPlr then
				hum.Health -= 55
				if hum.Health <= 0 then
					local oMoney = oPlr.leaderstats.Money.Value
					oPlr.leaderstats.Money.Value -= oMoney/10
					ownerPlr.leaderstats.Money.Value += oMoney/10
				end
			else
				hum.Health -= 75
				if hum.Health <= 0 then
					ownerPlr.leaderstats.Money.Value += 10
				end
			end
		end
	end
end

tool:WaitForChild("Blade").Touched:Connect(damage)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

you kind of have to explain whats wrong…
good job giving the items, but i dont really understand whats wrong with this script.

it just doesnt do any damage for some reason

hum.Health -= 55 looks weird.
try:
hum:TakeDamage(amount)

The script still doesn’t work with the change

I think I managed to fix it.

local tool = script.Parent

local deBounce = false

local function damage(oPart)
	if deBounce == false then
		local character = oPart.Parent
		local humanoid = character:FindFirstChild("Humanoid")

		if humanoid then
			local ownerChar = tool.Parent
			local ownerPlr = game:GetService("Players"):GetPlayerFromCharacter(ownerChar)

			if character ~= ownerChar then
				local oPlr = game:GetService("Players"):GetPlayerFromCharacter(character)
				if oPlr then
					deBounce = true
					humanoid:TakeDamage(55)
					if humanoid.Health <= 0 then
						local oMoney = oPlr.leaderstats.Money.Value
						oPlr.leaderstats.Money.Value = oMoney - oMoney/10
						ownerPlr.leaderstats.Money.Value = ownerPlr.leaderstats.Money.Value + oMoney/10
					end
					task.wait(.5)
					deBounce = false
				else
					deBounce = true
					humanoid:TakeDamage(75)
					if humanoid.Health <= 0 then
						ownerPlr.leaderstats.Money.Value = ownerPlr.leaderstats.Money.Value + 5
					end
					task.wait(.5)
					deBounce = false
				end
			end
		end
	end
end

tool:WaitForChild("Blade").Touched:Connect(damage)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.