Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] Why does my localscript not see that i've changed a value?

Asked by 3 years ago
Edited 3 years ago

Hey so basicaly i asked a question about 3 - 2 days ago i think but couldnt find a solution. But i did find that the reason the script didnt work was because a local script never saw that i edited a value. So i was wondering if there is anyone that knows why this happened.

Logs:

114:11:56.573  applePickupScript thinks that heal.Value = 20  -  Server
214:11:56.574  Script says that actall value is 20  -  Server - Script:2 -- The actuall value
314:11:56.591  LocalScript thinks that heal.Value = 0  -  Client - LocalScript:6 -- doesnt see the new value

applePickupScript

01script.Parent.Touched:Connect(function(hit)
02 
03    if hit.Parent:FindFirstChild("Humanoid") then
04        local player = game.Players[hit.Parent.Name]
05        local audio
06 
07        if script.Parent.AppleQuality.Value == 1 then
08            audio = hit.Parent.Head.audio1
09        else
10            audio = hit.Parent.Head.audio2
11        end
12 
13        player.leaderstats.Apples.Value = player.leaderstats.Apples.Value + script.Parent.AppleQuality.Value
14        audio:Play()
15 
View all 30 lines...

LocalScript

1local humanoid = game.Players.LocalPlayer.Character.Humanoid
2 
3while wait() do
4    humanoid.Health = humanoid.Health + game.ReplicatedStorage.heal.Value
5    if game.ReplicatedStorage.heal.Value >= 0 then game.ReplicatedStorage.heal.Value = 0 end
6end

Note that the value is located in ReplicatedStorage

Thanks in advance!

Solution : I was updating a server value from a local script (see line 5 in local script) which obviosly doesnt work, so i had to create a remote that updated the value instead and run the remote in the local script. Here is the working script:

1local humanoid = game.Players.LocalPlayer.Character.Humanoid
2 
3while wait() do
4    humanoid.Health = humanoid.Health + game.ReplicatedStorage.heal.Value
5    if game.ReplicatedStorage.heal.Value >= 1 then
6        game.ReplicatedStorage.reset:FireServer(0)
7    end
8end

Remote :

1game.ReplicatedStorage.reset.OnServerEvent:Connect(function(plr, val)
2    game.ReplicatedStorage.heal.Value = val
3end)

Thanks to icodealone#6535 on discord who gave me the answer to my problem and thanks to everyone who tried to help :)

Answer this question