I need help with with fixing this healing bug

Hi everyone, I recently made an item that heals other players to add more team-based gameplay into my game. I found this strange issue while testing it that causes health healed to jump back, and doesn’t heal the player at all.
This is a demonstration, keep an eye on the other player’s health:

The stranger thing is that it can heal dummies, but it can’t heal players for some reason. There’s no errors in the consoles either. I think the problem might be from the script being a local script, but I’m not sure and can’t convert it to a normal script without the entire script breaking.

Thanks for reading, if you know how to fix this then please don’t hesitate to tell me.

2 Likes

Yes the reason for this is because it is on a server script. Every couple seconds the server increases the health of the dummy so the following will happen:

Dummy is at 10 hp,
Local script changes the health to 30 but the Server still thinks that it is 10.
Server increases the health by 2, so now the dummy's hp is 12

You should use a remote event or something to tell the server to update the health.

1 Like

What I would do is, use a local script like you are doing and sending a remote event to the server, the parameters you should send over is the player that it hit. That way the server can see it and it’s more secure this way also, when the server recieve the event just find the character from the player that touched it and update there health with maybe playerHit.Character.Humanoid.Health += 10 -- Adds 10 to their current health

1 Like

Like what others have mentioned, you have to make use of a server script in order to chnge the health from a local script, I would recommend doing what @XdJackyboiiXd21 mentioned and make a RemoteEvent where you give it the health you want to set it to and the humanoid to set the health to and write some code to set the health of the humanoid which should do it without causing conflictions between the health script and the healing script you have, which is also why it’s not working for players, since your Dummy/NPC may not have had a health script inside it

1 Like

Thank you to everyone for your suggestions, but I don’t know how to get the function to work. I made the healing script fire the event, and I’ve spent a bit trying to get it to work. A script in ServerScriptService is what is supposed to heal the player the user clicked. The problem is that I have no idea what to put into the script, since I don’t have much experience with using events. Here’s the script for the tool, it uses a TF2 medigun script which I modified a lot, I think I have to put human.Humanoid.Health = human.Humanoid.Health + 0.6 in the event, but again I’m not sure how to implement it.
Here’s the enitre script for the tool:

local beam = Instance.new("Part")
beam.formFactor = 0
beam.Transparency = 0.1
beam.CanCollide = false
beam.Anchored = true
beam.Locked = true
local Player = game:GetService("Players").LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Human = Character:WaitForChild("Humanoid")
local EquipTrack
local IdleTrack
local HealTrack

beam.Name = "Beam"
beam.Size = Vector3.new(0.6,0.6,0.6)
local m = Instance.new("BlockMesh")
m.Parent = beam
local h = Instance.new("Hint")

local Equip = script:WaitForChild("Equip")
local Idle = script:WaitForChild("Idle")
local Heal = script:WaitForChild("Heal")

--

local uber = game.ReplicatedStorage.uber.Value
local ubercharging = false
local healing = ""
local healingnow = false
local equipped = false
local abletouber = true
local CanUBer = false

function healPlayer(human)
	local player = game.Players:GetPlayerFromCharacter(human)
	script.Parent.Handle.HealStart:Play()
	if player ~= nil and player.Neutral == false and player.TeamColor ~= game.Players:GetPlayerFromCharacter(script.Parent.Parent).TeamColor then
		spark()
	end

	healing = human
	healingnow = true
	print("TOOL EVENT: " .. script.Parent.Parent.Name:upper() .. " is HEALING " .. human.Name:upper())
	if not HealTrack then HealTrack = Human:LoadAnimation(Heal) end
	HealTrack:Play()
	beam.Parent = script.Parent
	beam.BrickColor = BrickColor.new("Bright blue")
	beam.Material = Enum.Material.ForceField
	while healingnow == true do
		if (healing.Torso.Position - script.Parent.H8.Position).magnitude <= 32 then
			beam.CFrame = CFrame.new((human.Torso.Position + script.Parent.H8.Position) / 2, human.Torso.Position) * CFrame.fromEulerAnglesXYZ(1.57,0,0)
			m.Scale = (m.Scale - Vector3.new(0,m.Scale.y,0)) + Vector3.new(0,0.4,0)
			m.Scale = m.Scale + Vector3.new(0,(human.Torso.Position - script.Parent.H8.Position).magnitude - 1,0)
			game.ReplicatedStorage.Healthy:FireServer()
			script.Parent.H8.ParticleEmitter.Enabled = true
			script.Parent.H8.PointLight.Enabled = true
			if uber < 1500 and abletouber == true then
				uber = uber + 1
			end
			h.Text = "Ubercharge: ("
			for i = 1, math.floor(uber / 100) do
				h.Text = h.Text .. "|"
			end
			for i = 1, 10 - math.floor(uber / 100) do
				h.Text = h.Text .. "."
			end
			h.Text = h.Text .. ")"
		else
			healingnow = false
			healing = ""
			ubercharging = false
			beam.Parent = nil
			spark()
			break
		end
		wait(0.01)
	end
end

function spark()
	print("TOOL EVENT: " .. script.Parent.Parent.Name:upper() .. " has SPARKED with " .. script.Parent.Name:upper())
	script.Parent.H8.PointLight.Enabled = true
	script.Parent.Handle.End:Play()
	script.Parent.H8.Sparked.Enabled = true
	script.Parent.H8.ParticleEmitter.Enabled = false
	wait(0.1)
	script.Parent.H8.Sparked.Enabled = false
	if HealTrack then HealTrack:Stop() end
end

function onButton1Down(mouse)
	if mouse.Target == nil then
		return
	end

	if mouse.Target.Parent == nil then
		return
	end

	if mouse.Target.Parent:FindFirstChild("Humanoid") ~= nil then
		healPlayer(mouse.Target.Parent)
	else
		spark()
	end
end

function onButton1Up()
	healingnow = false
	healing = ""
	ubercharging = false
	m.Scale = (m.Scale - Vector3.new(0,m.Scale.y,0)) + Vector3.new(0,1,0)
	beam.Parent = nil
	script.Parent.H8.PointLight.Enabled = false
	script.Parent.H8.ParticleEmitter.Enabled = false
	script.Parent.H8.Sparked.Enabled = false
	if HealTrack then HealTrack:Stop() end
end

function onKeyDown(key)
	key:lower()
	if key == "e" then
		if uber == 1500 then
			script.Parent.H8.UBER.Enabled = false
			abletouber = false
			local things = {}
			uber = 0
			h.Text = "Ubercharge: ("
			for i = 1, math.floor(uber / 100) do
				h.Text = h.Text .. "|"
			end
			for i = 1, 10 - math.floor(uber / 100) do
				h.Text = h.Text .. "."
			end
			h.Text = h.Text .. ")"
			local c = script.Parent.Parent:GetChildren()
			for i = 1, #c do
				if c[i].className == "Part" then
					c[i].Reflectance = c[i].Reflectance + 0.5
					table.insert(things, c[i])
				end
			end
			local ff = Instance.new("ForceField")
			script.Parent.Handle.POPPED.Playing = true
			table.insert(things, ff)
			ff.Parent = script.Parent.Parent
			if healing ~= "" then
				local b = healing:GetChildren()
				for i = 1, #b do
					if b[i].className == "Part" then
						b[i].Reflectance = b[i].Reflectance + 1
						table.insert(things, b[i])
					end
				end
				local sf = Instance.new("ForceField")
				sf.Parent = healing
				table.insert(things, sf)
			end
			wait(20)
			script.Parent.Handle.POPPED:Stop()
			local c = things
			for i = 1, #c do
				if c[i].className == "Part" then
					c[i].Reflectance = c[i].Reflectance - 1
				elseif c[i].className == "ForceField" then
					c[i]:Remove()
					spark()
				end
			end
			abletouber = true
		end
	end
end

function onEquip(mouse)

	script.Parent.Handle.Equip:Play()
	if not EquipTrack then EquipTrack = Human:LoadAnimation(Equip) end
    EquipTrack:Play()	
	wait(1.05)
	if not IdleTrack then IdleTrack = Human:LoadAnimation(Idle) end
	IdleTrack:Play()
	h.Parent = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	h.Text = "Ubercharge: ("
	for i = 1, math.floor(uber / 100) do
		h.Text = h.Text .. "|"
	end
	for i = 1, 10 - math.floor(uber / 100) do
		h.Text = h.Text .. "."
	end
	h.Text = h.Text .. ")"
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	mouse.Button1Up:connect(onButton1Up)
	mouse.KeyDown:connect(onKeyDown)
end

function onUnequip()
	h.Parent = nil
	healing = ""
	healingnow = false
	ubercharging = false
	beam.Parent = nil
	m.Scale = (m.Scale - Vector3.new(0,m.Scale.y,0)) + Vector3.new(0,1,0)
	if IdleTrack then IdleTrack:Stop() end
	if EquipTrack then EquipTrack:Stop() end
	if HealTrack then HealTrack:Stop() end
	script.Parent.H8.ParticleEmitter.Enabled = false
	script.Parent.H8.UBER.Enabled = false
	script.Parent.H8.Sparked.Enabled = false
	end

script.Parent.Equipped:connect(onEquip)

script.Parent.Unequipped:connect(onUnequip)

while true do
	for i = 1, 5 do
		m.Scale = m.Scale + Vector3.new(0.1,0,0.1)
		wait(0.1)
	end
	for i = 1, 5 do
		m.Scale = m.Scale - Vector3.new(0.1,0,0.1)
		wait(0.1)
	end
end

What is in that Healthy RemoteEvent? Is it for the healing? For it to work, you have to specify a parameter for the human you’re trying to heal, which isn’t difficult

game.ReplicatedStorage.Healthy:FireServer(human)

This will send human over to the RemoteEvent, and your remote event’s onServerEvent, just do what you wrote

Healthy was for healing, and I replaced the old “game.ReplicatedStorage.Healthy:FireServer” with your new one. It does fire properly now, but the console keeps showing me this error:image

Line 2 is human.Humanoid.Health + 0.6, not sure what I’m doing wrong this time, but I think we’re almost done to fixing it.

Could you show me what you have in your onServerEvent

game.ReplicatedStorage.Healthy.OnServerEvent:Connect(function()

human.Humanoid.Health = human.Humanoid.Health + 0.6

end)

That’s all I have

Do this

game.ReplicatedStorage.Healthy.OnServerEvent:Connect(function(player, human)

human.Humanoid.Health = human.Humanoid.Health + 0.6

end)

You didn’t specify the parameter for the humanoid you sent it. Also you have to put a first parameter for your player since it is automatic and if we didn’t, it would’ve treated human as your player instance, which would’ve errored

1 Like

Thanks for helping me with this, I don’t really know much about remotes so sorry if I wasted any time. I’ll probably keep trying to use them, so I can learn more.
And thanks to everyone for suggesting ideas too.

1 Like

You’re welcome! And it’s okay, you’ll get better at understanding remotes in the future! If you have anymore issues don’t be afraid to make another post!

2 Likes