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

I got this from a YT tutorial but it wont deal damage? Help please?

local tool = script.Parent

local damage = 25

local inner = tool.Emitter.Inner	
local outer = tool.Emitter.Inner

tool:WaitForChild("Blade").Touched:Connect(function (hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid:TakeDamage(damage)
	end
end)

tool:WaitForChild("RemoteEvent").OnServerEvent:Connect(function (player, state)
	if state then
		tool.Emitter.Inner.Enabled = true
		tool.Emitter.Outer.Enabled = true
	else
		inner.Parent = nil
		outer.Parent = nil
		
		inner.Enabled = false
		outer.Enabled = false
		
		wait(2)
		
		inner.Parent = tool.Emitter
		outer.Parent = tool.Emitter
		
	end
end)

it wont deal damage and there isnt a error

1 answer

The problem is that you there isn't a member called "Health" when it deals damage. So essentially, the script looks to see whatever touches it and finds a humanoid then tries to deal damage, since there's nothing called health it doesn't do anything.

A solution to this could be

local tool = script.Parent

local inner = tool.Emitter.Inner    
local outer = tool.Emitter.Inner

tool:WaitForChild("Blade").Touched:Connect(function (hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25
    end
end)

tool:WaitForChild("RemoteEvent").OnServerEvent:Connect(function (player, state)
    if state then
        tool.Emitter.Inner.Enabled = true
        tool.Emitter.Outer.Enabled = true
    else
        inner.Parent = nil
        outer.Parent = nil

        inner.Enabled = false
        outer.Enabled = false

        wait(2)

        inner.Parent = tool.Emitter
        outer.Parent = tool.Emitter

    end
end)

Please correct me if I am wrong, I haven't tested it out.

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