Alright guys so I am trying to make a script where you can heal yourself or other players with a medkit similar to a story game system like ftz or break in. here is the script I have so far its a local script in the tool.
-- Create the Heal function
local function Heal(player)
-- Check if the player is alive
if player.Character and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
-- Create a selection box on the player
local selectionBox = Instance.new("SelectionBox")
selectionBox.Adornee = player.Character
selectionBox.LineThickness = 0.1
selectionBox.Parent = player.Character
-- Wait for a short duration to show the selection box
wait(1)
-- Heal the player
player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
-- Remove the selection box
selectionBox:Destroy()
end
end
-- Handle equipped event
tool.Equipped:Connect(function(mouse)
-- Create a selection box for the local player
local selectionBox = Instance.new("SelectionBox")
selectionBox.Adornee = game.Players.LocalPlayer.Character
selectionBox.LineThickness = 0.1
selectionBox.Parent = game.Players.LocalPlayer.Character
-- Wait for a short duration to show the selection box
wait(1)
-- Remove the selection box
selectionBox:Destroy()
end)
-- Handle mouse button click
tool.Activated:Connect(function()
-- Check if the player is healing themselves
local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
Heal(game.Players.LocalPlayer)
end
end)