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

How do I make my foot do damage with r15 while doing an Animation?

I have put the code below the green part is the difficulty I am having. I don't really know what to do next or what I'm doing wrong. I'm trying to play an animation and then have the foot do damage.


foot = game.Players.LocalPlayer.Character.RightFoot
player = game.Players.LocalPlayer
mouse = player:GetMouse()
enabled = true
kobe = false

function KeyD(key)
	if enabled then
		enabled = false
	key = key:lower()
	local hotkey = script.bby
	local char = player.Character
	if key == hotkey.Value then
		local roundhouseright = Instance.new("Animation")
		roundhouseright.AnimationId = "http://www.roblox.com/Asset?ID=884273622"
		local animtrak = char.Humanoid:LoadAnimation(roundhouseright)
		animtrak:Play()
		kobe = true
		if kobe == true then 
			script.Parent.touched:connect(function(hit)
				--I don't know what to do after this--
					end
					
				end
			end)
		
		end
	end
	wait(.75)
		enabled = true
	end
end

mouse.KeyDown:connect(KeyD)
		

2 answers

Try doing this. Haven't tested this but it should work.

foot = game.Players.LocalPlayer.Character.RightFoot
player = game.Players.LocalPlayer
mouse = player:GetMouse()
enabled = true
kobe = false

function KeyD(key)
    if enabled then
        enabled = false
    key = key:lower()
    local hotkey = script.bby
    local char = player.Character
    if key == hotkey.Value then
        local roundhouseright = Instance.new("Animation")
        roundhouseright.AnimationId = "http://www.roblox.com/Asset?ID=884273622"
        local animtrak = char.Humanoid:LoadAnimation(roundhouseright)
        animtrak:Play()
        kobe = true
        if kobe == true then 
            script.Parent.Touched:connect(function(hit)
                local plr = hit.Parent:findFirstChild("Humanoid")
        if (plr ~= nil) then
                plr.Health = plr.Health - 5 -- Change the amount to change the damage.
        end
                    end

                end
            end)

        end
    end
    wait(.75)
        enabled = true
    end
end

mouse.KeyDown:connect(KeyD)

I think "Touched" has to be capital, and "Connect" works better capitalized (idk why they did this, they are asking for broken games)also try seeing how long the animation is( print numbers and round to how long you think it is or stop it at a certain point, or check anim editor) and do:

kobe = true
local animtime = 5 -- animation time length
if kobe == true then
	script.Parent.Touched:Connect(function(hit)
	for i = 1, animtime, .1 do
 		if hit.Parent:FindFirstChild("Humanoid") ~= nil then --if you hit a body part
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20 --Replace 20 with the damage
		 elseif hit.Parent.Parent:FindFirstChild("Humanoid") ~= nil then --if you hit an accessory's or tool's handle
			hit.Parent.Parent.Humanoid.Health = hit.Parent.Parent.Humanoid.Health - 20 --	Replace 20 with the damage again
		end
	wait(.1) --prevents crash, checks every .1 second
end

This may not work, and if it doesnt, try this :

local animtime = 5 --change to time of animation
	repeat if hit.Parent:FindFirstChild("Humanoid") ~= nil then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20
		 elseif hit.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
			hit.Parent.Parent.Humanoid.Health = hit.Parent.Parent.Humanoid.Health - 20
		end until i == animtime--yes this is one line technically,  it is up if you want to consolidate it but it is not needed, personally I think it is more organized this way.

Now if that doesn't work, message me and I'll try to help you more.

~~CamScripted, don't complain over spilled milk, spilled milk on a computer, or spilled milk in a new car. Evaluate and fix it. There is always something worse.

2 comments

0

Not sure what to do for "Function Hit" I don't know what the function should do.

0

How when I press f it shows the animation (and you can spam it) but it doesn't do damage

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