So, I am making a simple game about collecting apples to heal yourself, you need to collect enough apples in order to not die. You take x amount of damage per second.
And the problem is that when I collect an apple the first time everything goes as planned and I get healed, but the second time I collect an apple I do not heal. I have not seen anyone else get the same issue and was wondering how to fix this. I also do not get any errors in the output.
Part of a script that tells a value to get updated to 20
game.ReplicatedStorage.heal.Value = 20
LocalScript that handles the new value and updates your health
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local heal = game:GetService("ReplicatedStorage"):WaitForChild("heal")
while wait() do
humanoid.Health = humanoid.Health + game.ReplicatedStorage.heal.Value
if heal.Value >= 1 then heal.Value = 0 end
end
oh i probably should've mentioned that you collect the apples by touching them, not clicking and the script that tells the localscript to heal you is in the apple
UPDATE : Ok so i found that the local script that handles the new value doesnt see that the value has changed the second time i grab an apple. Does anyone know why this is happening?
Log:
14:11:56.573 applePickupScript thinks that heal.Value = 20 - Server
14:11:56.574 Script says that actall value is 20 - Server - Script:2 -- Script that i used for debugging checking which script is right.
14:11:56.591 LocalScript thinks that heal.Value = 0 - Client - LocalScript:6
Check out this post for the soultion to my problem https://scriptinghelpers.org/questions/123520/solved-why-does-my-localscript-not-see-that-ive-changed-a-value

4 comments
oh i probably should've mentioned that you collect the apples by touching them, not clicking and the script that tells the localscript to heal you is in the apple.
Heal them from server scripts. if its touch change the first line to script.Parent.Touched instead of click detector.mouseclick
You can directly heal the player when they touch instead of updating a value. touched param is the part that touched (probably the players legs/feet) so do if touch.parent (which is the players character) :findfirstchild'humanoid' then add the health to the humanoid
I tried healing the player directly from the server script but that didn't work either