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
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