Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this script deal damage?

Asked by 8 years ago

This script is for a kicking animation, and I want it to deal damage whenever the players right leg (the one in the animation) hits another player.



local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:WaitForChild("Humanoid") local Mouse = Player:GetMouse() local kicking = Instance.new("Animation", Humanoid) kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670" local function keyDown(key) key = key:lower() if key == 't' then local animTrack = Humanoid:LoadAnimation(kicking) animTrack:Play() end end Mouse.KeyDown:connect(keyDown)

2 answers

Log in to vote
-2
Answered by 8 years ago

sure. [UPDATED]

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")


local Mouse = Player:GetMouse()

local kicking = Instance.new("Animation", Humanoid)

kicking.AnimationId = "http://www.roblox.com/item.aspx?id=273619670"

local function keyDown(key)
    key = key:lower()
    if key == 't' then
        local animTrack = Humanoid:LoadAnimation(kicking)
        animTrack:Play() 
    end
 end 

function checkHit()
    local rLeg = Character:WaitForChild("Right Leg")
    local damage = 15

    rLeg.Touched:connect(function(toucher)
      if toucher.Parent. Humanoid then
          local hitHuman = toucher.Parent.Humanoid
         hitHuman.Health = hitHuman.Health - damage
     elseif toucher.Humanoid then
         local hitHuman2 = toucher.Humanoid
         hitHuman2.Health = hitHuman2.Health - damage
     end 
end)
    end)
end

Mouse.KeyDown:connect(keyDown, checkHit)
0
What would I do to check if it was a humanoid? 64batsalex 45 — 8y
0
you could try: if toucher.Parent.Humanoid or toucher.Humanoid then humanoid.Health = humanoid.Health - damage GlitchMasta47 7 — 8y
0
It keeps saying that It expects a" )" to close at line 24, but that still doesn't work 64batsalex 45 — 8y
0
rLeg.Touched:connect(function(toucher) if toucher.Parent. Humanoid then local hitHuman = toucher.Parent.Humanoid hitHuman.Health = hitHuman.Health - damage elseif toucher.Humanoid then local hitHuman2 = toucher.Humanoid hitHuman2.Health = hitHuman2.Health - damage end end) GlitchMasta47 7 — 8y
View all comments (2 more)
0
I tested it on a model and nothing happend ( I removed the end on line 33) 64batsalex 45 — 8y
0
The model had a Humanoid in it 64batsalex 45 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Glitch you're right but the Player.Character or Player.CharacterAdded:wait() the "player" is a nil value so it would have to be changed or it would bug and you would have to fix the script but gg GlitchMaster.

0
WHat do I do to change it? 64batsalex 45 — 8y
0
I might ask a friend that is a Scripter about it and I will get back to you soon. sammt1234554321 0 — 8y
0
Yea, Thanks! 64batsalex 45 — 8y

Answer this question