I dont really understand, how would I know if a player’s distance is close enough to kill? would the script look like this?
Lets pretend the dummy is a ko’d player
local player = game.Players.LocalPlayer
local target = game.Dummy
local distance = player:DistanceFromCharacter(Target.HumanoidRootPart.CFrame.Position)
local player = game.Players.LocalPlayer
local target = workspace.Dummy
local distance = player:DistanceFromCharacter(target.HumanoidRootPart.Position)
if distance < 8 then
print'close enough to kill'
else
print("too far from target", distance)
end
would this work? But how about monsters that you knock out (npcs)
local killables = {}
for i, v in pairs(game.Players:GetChildren()) do
local targetchar = v.Character
local distance = player:DistanceFromCharacter(targetchar.HumanoidRootPart.Position)
if distance < 8 then
table.Insert(killables, v.Name)
else
print("too far from target", distance)
end
end
Just do the same thing you did with the players, but with the NPCs’ characters instead
local Players = game:GetService'Players'
local LocalPlayer = Players.LocalPlayer
local KillableCharacters = {}
for i, Player in pairs(Players:GetPlayers()) do
local TargetCharacter = Player.Character
local Distance = LocalPlayer:DistanceFromCharacter(TargetCharacter.HumanoidRootPart.Position)
if Distance < 8 then
table.Insert(KillableCharacters, TargetCharacter)
end
end
-- assuming you have a folder in workspace named "NPCs" that has all NPCs
for i, NPC in pairs(workspace.NPCs:GetChildren()) do
local TargetCharacter = NPC
local Distance = LocalPlayer:DistanceFromCharacter(TargetCharacter.HumanoidRootPart.Position)
if Distance < 8 then
table.Insert(KillableCharacters, TargetCharacter)
end
end
local Players = game:GetService'Players'
local LocalPlayer = Players.LocalPlayer
local UserInput = game:GetService("UserInputService")
local db = true
local KillableCharacters = {}
UserInput.InputBegan:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.V then
if db then
db = false
for i, Player in pairs(Players:GetPlayers()) do
local TargetCharacter = Player.Character
local Distance = LocalPlayer:DistanceFromCharacter(TargetCharacter.HumanoidRootPart.Position)
if Distance < 8 then
table.Insert(KillableCharacters, TargetCharacter)
end
end
for i, NPC in pairs(workspace.NPCs:GetChildren()) do
local TargetCharacter = NPC
local Distance = LocalPlayer:DistanceFromCharacter(TargetCharacter.HumanoidRootPart.Position)
if Distance < 8 then
table.Insert(KillableCharacters, TargetCharacter)
end
end
local randomkillable = KillableCharacters[math.random(1,#KillableCharacters)]
--plays an animation
local killablehum = randomkillable:FindFirstChidOfClass('Humanoid')
killablehum.Health = 0
wait(0.1)
db = true
end
end
end)
Setting the humanoid’s health to 0 in a LocalScript won’t replicate to the server, you should fire a remote event instead and then set the health on the server