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

how would i make a player or npc who got hit play an animation?

Asked by
Roguzy 2
4 years ago

so im trying to make a nice combat system for my game but i am a fairly new to scripting,but to further elaborate in my question how would i go about making a player/npc who has been punched by another player play an animation showing that the hit has landed again im pretty new to scripting so my attempt at this is laughable but here it is :

local Player = game.Players.LocalPlayer local Character = Player.Character local c = Player.Character

if Player:TakeDamage(5) -- the amount of damage a single punch does then

 local Track = Instance.new("Animation")
        Track.AnimationId = "rbxassetid://4787043272"
        local Anim = c.Humanoid:LoadAnimation(Track)
        Anim:Play()

end

i put this in StarterPlayer scripts

1 answer

Log in to vote
0
Answered by
Geobloxia 251 Moderation Voter
4 years ago
Edited 4 years ago

Make sure it is a local script

local player = game.Players.LocalPlayer
local character = player.Character
local hum = character:WaitForChild("Humanoid")

local Track = Instance.new("Animation")
if hum.Health <= 95 and character ~= nil then
       Track.AnimationId = "rbxassetid://4787043272"
       local Anim = hum:LoadAnimation(Track)
       Anim:Play()
end

Put script in NPC and put this:

local character = script.Parent
local hum = character:WaitForChild("Humanoid")

while true do
    wait(0.1) -- cooldown so it doesn't
    -- crash
    if hum.Health <= 95 and character ~= nil then
    local Track = Instance.new("Animation")
        Track.AnimationId = "rbxassetid://4787043272"
        local Anim = hum:LoadAnimation(Track)
        Anim:Play()
    break
    end
end
0
I'm thinking maybe a while loop might work. Geobloxia 251 — 4y
0
if i would want to do this for An npc what would i do then? would i just put this script in the npc and change up a few variables? Roguzy 2 — 4y
0
Yes, because the LocalPlayer wouldn't work. Geobloxia 251 — 4y
0
hmm this didn't work out and nothing is showing up in output for the npc Roguzy 2 — 4y
View all comments (2 more)
0
Try that. I edited it. Geobloxia 251 — 4y
0
Depending on the objective, you can include the "break" or remove it. Geobloxia 251 — 4y
Ad

Answer this question