How can I make a medikit like this?

Hi, I am trying to make a medikit that is able to heal others by clicking on them. If you equip the item then you should see boxes around the players. If you click on the box of the player then the player will get healed. I already have the healing script so I dont need that script. Does anybody know how I can make something like this?

2 Likes

I think you should use a SelectionBox object as well as mouse.hit to detect if the player is hovering over a player’s character model.

2 Likes

The SelectionBox object should be parented to the target player’s character. I think you could also use raycasting for detecting what the mouse is pointing at.

1 Like

Should I use a localscript in startercharacterscripts that makes a new instance (the selectionbox) and make it group into every players torso? Or should I use a serverscript? (I might now answer for the next 1-2 hours because I dont have much time right now)

Rather than a selection box, roblox has a new tool called “Highlight”, which is 100x better than selectionbox.

3 Likes

Hello!

You could do something using the new highlight tool to highlight the player using mouse.Parent.Parent and use the same technique to heal them!

1 Like

Look into this gear’s scripts.

To be fair, you could look at an ESP exploit script to see how they made the boxes around the player. Then you can write that in your own code using the concept you mentioned.

Should I check if the mouse of the player with the medikit touched the player with the mouse and then check if it has a humanoid?

See if this works, put it in a local script inside your tool.

local Players = game:GetService("Players") 

local player = Players.LocalPlayer -- Getting The Player

local mouse = player:GetMouse() --Getting The Mouse

local function onButton1Down()
	if mouse.Target.Parent:FindFirstChild("Humanoid") then -- if the targets parent has a humanoid then its a player
		local hum = mouse.Target.Parent.Humanoid -- get the targets humanoid
		hum.Health += 10 -- add ten to the humanoids health (this value can be altered to your liking)
	end
end

mouse.Button1Down:Connect(onButton1Down) -- call the function if the mouse is down
3 Likes

It seems to work. I will modify it a bit and use my own heal script in there. Thanks for the help!

Hiya, thanks for marking it as a solution and I hope you enjoy your medkit, please do feel free to contact me via Roblox message or reply to me if you have any further enquires!
:grinning:

For the “boxes” that surround the player, you can use a Highlight. That being said, here’s how you would do everything else. And for the mouse detection, you can use Mouse.Target for this. With that being said, here’s the scripts!

-- server script
local tool = script.Parent
local heal = tool:WaitForChild("Heal")

heal.OnServerEvent:Connect(function(player, target)
	local char = target.Character
	local hum = char:WaitForChild("Humanoid")
	
	if hum then
		hum.Health += 10
	end
end)
-- local script
local PS = game:GetService("Players")

local player = PS.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local heal = tool:WaitForChild("Heal")
local highlights = {}

tool.Equipped:Connect(function()
	for _,v in ipairs(PS:GetPlayers()) do
		local char = v.Character
		local highlight = Instance.new("Highlight") do
			highlight.Parent = char
			table.insert(highlights, highlight)
		end
	end
end)

tool.Unequipped:Connect(function()
	for _,v in ipairs(highlights) do
		v:Destroy()
	end
end)

tool.Activated:Connect(function()
	if mouse.Target then
		local char = mouse.Target:FindFirstAncestorWhichIsA("Model")
		local player = char and PS:GetPlayerFromCharacter(char)
		
		if player then
			heal:FireServer(player)
		end
	end
end)

Your tool should look something like this.
image


3 Likes