I made something like this a while back for the fun of it. Basically;
Have a remote event that fires when the key bind is pressed
Have a script that listens for that event, and checks for nearby players that have an attribute, i.e. “knocked_down”
Have a module script in the weapon with a function that the previous script will run when a target is found
Here’s an example;
--Server script
local Players = game:GetService("Players");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local executeEvent = ReplicatedStorage.Execute; --Name this whatever, execute is just what I used at the time
function getNearestPlayer(executingChar)
local maxDist = 15; --This is the radius that you can execute someone.
local target;
for _, plr in next, Players:GetPlayers() do
local char = plr.Character;
local hum = char:FindFirstChildOfClass("Humanoid");
local dist = (executingChar.PrimaryPart.Position - char.PrimaryPart.Position).Magnitude;
if hum.Health > 0 and char:GetAttribute("knocked_down") and dist < maxDist then
--Make sure the target's alive, has the knocked_down attribute, and is close enough.
maxDist = dist;
target = char;
end
end
return target;
end
function onExecuteRequest(plr)
local char = plr.Character;
local hum = char:FindFirstChildOfClass("Humanoid");
local weapon = char:FindFirstChildOfClass("Tool");
local target = getNearestPlayer(plr);
if target and hum.Health > 0 and weapon then
local config = require(weapon:FindFirstChild("Config"));
if config and config.execute then --Checks for a config, and if it has an execute function
config.execute(char, target);
end
end
end
executeEvent.OnServerEvent:Connect(onExecuteRequest);
--Module script
local tool = script.Parent;
local executeAnim = tool.execute_anim_here;
local Config = {};
function Config.execute(user, target)
local userHum = user:FindFirstChildOfClass("Humanoid");
local targetHum = user:FindFirstChildOfClass("Humanoid");
local animTrack = userHum:LoadAnimation(executeAnim);
animTrack:Play();
wait(1); --This is just a delay to let the animation play, you could also use animTrack.KeyframeReached
targetHum.Health = 0;
end
return Config;
You didn’t even give him any ideas on how to make it himself. No code, no inspiration, not even a direction to go in, you kinda just said ‘make it yourself, good luck bro’
I would reccomend having a downed bool value in the Humanoid, and once you press F send a raycast downwards to see if it hits a player, if the player is considered down, play the animation and the finish
The advice that people are giving you is very good, tell me how it went. I went along with what they said, made it in my own way, and came up with this.