Healing player not working

So I made a healing machine where you can heal yourself by pressing a SurfaceGui button. Inside the button is a local script containing this:

--Local script:
script.Parent.MouseButton1Click:Connect(function(player)
	game.ReplicatedStorage.Healing:FireServer(player)
end)

Then in ServerScriptService is a normal script that contains this:

--Script:
game.ReplicatedStorage.Healing.OnServerEvent:Connect(function(player)
	if player:FindFirstChild("leaderstats").Coins.Value >= 50 then
		player:FindFirstChild("leaderstats").Coins.Value -= 50
		player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
	end
end)

The problem is that the player isn’t healing and after clicking the button the 50 coins are taken away but aren’t saved by the datastore. I don’t know what to do.

Thank you for helping!

1 Like

Your code seems fine to heal the player, maybe try to change the local script to this

script.Parent.MouseButton1Click:Connect(function() --removed player, why was it even there?
	game.ReplicatedStorage.Healing:FireServer() --removed the player,  remote event automatically gets the player 
end)
2 Likes

first of you shouldn’t be using a remote event like that unless you want an exploiter to heal from any where on the map insted of just a healing machine. also you say it dosn’t save to the data store do you have a script that updates the data store otherwise you will need to update it ps place after you change the leadrstat int or eles it wont update

-- Replace with your data store names
game.DataStoreService:GetDataStore("CHANGE ME TO DATA STORE NAME"):SetAsync("CHANGE ME TO VARIBLE NAME" + player.UserId,player:FindFirstChild("leaderstats").Coins.Value)

i recomend you use a clickdetector insted of a text gui becuase they can be used in server scripts to prevent exploits like the one i mentiond earlier

also i tested the code

but it worked perfectly fine try adding a print to find the problem you have restoreing health

print(player.Character.Humanoid)

also as neviquatro mentioned

you do not need to add the player var to the function becuase remote events atomaticly send the plr what you are doing is sending the player to the remote function twice which is unnecessary

best of luck

2 Likes

You could still use a remove event just check the distance between the character and the the healing machine in the OnServerEvent

1 Like

I did this and got an error: Property “Animator.EvaluationThrottled” is not currently enabled. (x7)

are you animateing a humanoid or something else? from research online this is an error from animating something that is in replicated storage insted of the workspace i am rather confused by this error