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

Why won't my script do damage? There aren't any errors in output either

I've tried this

	mouse.KeyDown:connect(function(key)
		key = key:lower()
		if key == "e" then
			local ball = Instance.new("Part")
            ball.Shape = "Ball"
            ball.BrickColor = BrickColor.new("Really black")
            ball.Transparency = 0.5
            ball.TopSurface = "Smooth"
            ball.BottomSurface = "Smooth"
            ball.CanCollide = false
            ball.Anchored = false
            ball.Material = "Neon"
            ball.CFrame = torso.CFrame * CFrame.new(0,3,-12)
            local velocity = Instance.new("BodyVelocity", thotbegone)
            velocity.Velocity = torso.CFrame.lookVector * 90
            velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
            velocity.Parent = workspace
            function onTouch(part)
             local humanoid = ball.Parent:findFirstChild("Humanoid")
             if (humanoid ~= nil) then
                  humanoid.Health = 0
            end
end
		end
	end)

But the ball won't do damage, no errors or anything. I've tried using Touched and hit and everything I could do to see if anything else would work. But whatever I do the script won't work.

Ignore things like "torso", it's a variable farther up in the original script.

(at times i'll get an error that says the ball isnt a part of itself?)

1 comment

1 answer

KeyDown is deprecated, be sure to see InputBegan. Anyways, your code is nearly perfect! You created the function to deal damage, but you never triggered it! As well, you got a bit mixed up with variable reference withing the function. To fix your issue, you'd need to add a connection line, and correct your variable usage. In my answer, I'm going to join the connection line and function into one line, which should clean up the code better and make it easier for you to understand.

    mouse.KeyDown:connect(function(key)
        key = key:lower()
        if key == "e" then
            local ball = Instance.new("Part")
            ball.Shape = "Ball"
            ball.BrickColor = BrickColor.new("Really black")
            ball.Transparency = 0.5
            ball.TopSurface = "Smooth"
            ball.BottomSurface = "Smooth"
            ball.CanCollide = false
            ball.Anchored = false
            ball.Material = "Neon"
            ball.CFrame = torso.CFrame * CFrame.new(0,3,-12)
            local velocity = Instance.new("BodyVelocity", thotbegone)
            velocity.Velocity = torso.CFrame.lookVector * 90
            velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
            velocity.Parent = workspace
            ball.Touched:Connect(function(hit) -- Connection line. "hit" is the object that touched the ball
                if hit.Parent:FindFirstChild('Humanoid') then
                    hit.Parent.Humanoid.Health = 0 -- Alternatively, you could destroy the character's joints
                end
           end)
        end
    end)


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