I want to be able to use the medkits without having to drop them and pick them back up
When using them, I can pick them up, and I can use the first one in sucession, but if I equip a different one I have to drop all of the ones in my inventory, pick them up and use one again for it to work, and repeat each time
I tried fixing it with moving how the server finds it, using firing events but I can only make it work once without having to drop all of them, and if I start with them in my starter pack I have to drop all them and pick it up
This is the script inside of the tool
local Players = game:GetService("Players")
local remote = game.ReplicatedStorage:WaitForChild("UseMedkitEvent")
local tool = script.Parent
tool.Activated:Connect(function()
remote:FireServer(tool)
end)
This is the script inside of serverscriptstorage
local remote = game.ReplicatedStorage:WaitForChild("UseMedkitEvent")
local MAX_INJURY = 5
remote.OnServerEvent:Connect(function(player, tool)
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local healAmount = tool:GetAttribute("HealAmount") or 100
local injuryLoss = tool:GetAttribute("InjuryLoss") or 1
humanoid.Health = math.min(humanoid.MaxHealth, humanoid.Health + healAmount)
local injuryValue = player:FindFirstChild("Injury")
if not injuryValue then
injuryValue = Instance.new("NumberValue")
injuryValue.Name = "Injury"
injuryValue.Value = 2
injuryValue.Parent = player
end
injuryValue.Value = math.clamp(injuryValue.Value - injuryLoss, 0, MAX_INJURY)
print(player.Name .. " healed by " .. healAmount)
print("New Health: " .. humanoid.Health)
print("New Injury Level: " .. injuryValue.Value)
tool:Destroy()
end)```