local Tool = script.Parent
local players = game:GetService(“Players”)
– Variables
local Tool = script.Parent
local Handle = Tool:WaitForChild(“Handle”)
local Model = Tool:WaitForChild(“Model”)
local damagegui = game.ServerStorage.BillboardGui
local Slash = script:WaitForChild(“Slash”)
local Debounce = false
local PlayersHit = {}
local slashsound = script:WaitForChild(“SlashSound”)
local swingSound = script:WaitForChild(“SwingSound”)
local damage = 10
– Adds Welds
for i, Parts in pairs(Model:GetChildren()) do
if Parts:IsA(“BasePart”) then
local Weld = Instance.new(“WeldConstraint”)
Weld.Part0 = Parts
Weld.Part1 = Handle
Weld.Parent = Parts
end
end
– Animate
Tool.Activated:Connect(function()
if Debounce == false then
Debounce = true
swingSound:Play()
local Humanoid = Tool.Parent:WaitForChild(“Humanoid”)
local AnimTrack = Humanoid:LoadAnimation(Slash)
AnimTrack:Play()
task.wait(1)
Debounce = false
end
end)
– Damage
Handle.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(“Humanoid”) and Hit.Parent ~= Tool.Parent and not players:GetPlayerFromCharacter(Hit.Parent) then
if Hit.Parent:FindFirstChild(“Humanoid”).Health > 0 then
if Debounce == true and PlayersHit[Hit.Parent] == nil then
Hit.Parent:FindFirstChild(“Humanoid”):TakeDamage(damage)
slashsound:Play()
local cloneGui = damagegui:Clone()
PlayersHit[Hit.Parent] = true
cloneGui.Parent = Hit.Parent.Head
cloneGui.TheShadow.Text = damage
wait(.3)
cloneGui:Destroy()
task.wait(1)
PlayersHit[Hit.Parent] = nil
end
end
end
end)
With those scripts how can i make that when the player attacks the monster the monster like gets angry and chases the player that attacked him
add this code after local AttackSound = script.Ragh
local nowPlr = nil
local function StartToChaseThisPlayer(player)
repeat task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
until nowPlr ~= player
end
add this code after debounce = true
elseif hit.Name == "Handle" and Players:GetPlayerFromCharacter(hit.Parent.Parent) ~= nil and hit.Parent.Parent:FindFirstChild("Humanoid").Health > 0 then
player = Players:GetPlayerFromCharacter(hit.Parent.Parent)
nowPlr = player
StartToChaseThisPlayer(player)
end
hey but is there any chance that you can like make him chase the player that punched him for ever until the player is dead or the player kills the npc?
because it only like punches the player 1 time and thats it
local nowPlr = nil
local function StartToChaseThisPlayer(player)
repeat task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
until nowPlr ~= player
end
To this:
local nowPlr = nil
local function StartToChaseThisPlayer(player)
repeat task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
local playerHumanoid = playerCharacter:WaitForChild("Humanoid")
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
until nowPlr ~= player or playerHumanoid.Health <= 0 or humanoid.Health <= 0
end
local nowPlr = nil
local function StartToChaseThisPlayer(player)
repeat task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
local playerHumanoid = playerCharacter:WaitForChild("Humanoid")
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
until nowPlr ~= player or playerHumanoid.Health <= 0 or humanoid.Health <= 0
end
To this:
local nowPlr = nil
local function StartToChaseThisPlayer(player)
while true do task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
local playerHumanoid = playerCharacter:WaitForChild("Humanoid")
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
if nowPlr ~= player or playerHumanoid.Health <= 0 or humanoid.Health <= 0 then
break
end
end
end
local nowPlr = nil
local function StartToChaseThisPlayer(player)
while true do task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
local playerHumanoid = playerCharacter:WaitForChild("Humanoid")
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
if nowPlr ~= player or playerHumanoid.Health <= 0 or humanoid.Health <= 0 then
break
end
end
end
To this:
local nowPlr = nil
local function StartToChaseThisPlayer(player)
while true do task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
local playerHumanoid = playerCharacter:WaitForChild("Humanoid")
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
if nowPlr ~= player then
break
elseif playerHumanoid.Health <= 0 then
break
elseif humanoid.Health <= 0 then
break
end
end
end
local nowPlr = nil
local function StartToChaseThisPlayer(player)
repeat task.wait() local playerCharacter = player.Character or player.CharacterAdded:Wait()
local playerRoot = playerCharacter:WaitForChild("HumanoidRootPart")
local playerHumanoid = playerCharacter:WaitForChild("Humanoid")
print(playerHumanoid)
if playerRoot and (playerRoot.Position - rootPart.Position).Magnitude <= 25 and playerHumanoid then
humanoid:MoveTo(playerRoot.Position)
humanoid.MoveToFinished:Wait()
end
until nowPlr ~= player or playerHumanoid.Health <= 0 or humanoid.Health <= 0
end