I’m very new at scripting and I’m trying to make a melee weapon like boxing gloves to instantly kill a different player. However, I think I’ve hit a wall in my scripting knowledge.
local tool = script.Parent -- technically the handle
local boxing = tool.Parent --the actual tool
tool.Touched:Connect(function(h)
local Player = tool.Parent.Parent -- Player holding the tool
local Hum = h.Parent:FindFirstChild("Humanoid") -- Any opposing player
if Hum then
Hum.Health = 0 -- If the tool is being touched then the opposing player will die
end
if Player then
Player.Health = 100 -- Making sure the player will stay alive during their activation no matter what
end
end)
This script gets activated every time the tool/weapon is activated for a little while before being deactivated again. I REALLY NEED SOME HELP THANK YOU!
Usually the hierarchy for tool looks like this: Workspace > Character Name > Tool > Handle > Script
If you do local Player = tool.Parent.Parent you’re not actually getting the player but the character model since your tool is your handle under Character.Boxing.Tool
The touch event may also be shooting off multiple times in quick succession since theres no cooldown so i’d add that in aswell.
Might also want to change handle.Touched to another part under tool which is bigger, since the handles most likely going to be small and not really the thing hitting the enemy
The script should look something like this feel free to change any of the names to match it better.
local handle = script.Parent
local tool = handle.Parent
local cooldown = false -- prevents multiple hits in rapid succession
handle.Touched:Connect(function(hit)
if cooldown then return end
-- Find the hit character and humanoid
local hitChar = hit.Parent
local hitHum = hitChar:FindFirstChild("Humanoid")
-- Find the attacker using the tool and the humanoid
local attackerChar = tool.Parent
local attackerHum = attackerChar:FindFirstChild("Humanoid")
-- Sanity check AND checks if the hit isnt the same as the attacker
if hitHum and hitChar ~= attackerChar then
cooldown = true
hitHum.Health = 0 -- kill the dummy
if attackerHum then
-- you technically dont need this because of the sanity check but i'll leave it in depending on what your tool does
attackerHum.Health = 100
end
task.wait(0.5) -- change this to whatever you want
cooldown = false
end
end)