[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:
1 | 14 : 11 : 56.573 applePickupScript thinks that heal.Value = 20 - Server |
2 | 14 : 11 : 56.574 Script says that actall value is 20 - Server - Script: 2 |
3 | 14 : 11 : 56.591 LocalScript thinks that heal.Value = 0 - Client - LocalScript: 6 |
applePickupScript
01 | script.Parent.Touched:Connect( function (hit) |
03 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
04 | local player = game.Players [ hit.Parent.Name ] |
07 | if script.Parent.AppleQuality.Value = = 1 then |
08 | audio = hit.Parent.Head.audio 1 |
10 | audio = hit.Parent.Head.audio 2 |
13 | player.leaderstats.Apples.Value = player.leaderstats.Apples.Value + script.Parent.AppleQuality.Value |
16 | for i, v in pairs (workspace.spawnLocations:GetChildren()) do |
17 | if v.Position = = script.Parent.Position then |
18 | v.spotTaken.Value = false |
25 | game.ReplicatedStorage.heal.Value = 20 |
26 | script.Parent:Destroy() |
LocalScript
1 | local humanoid = game.Players.LocalPlayer.Character.Humanoid |
4 | humanoid.Health = humanoid.Health + game.ReplicatedStorage.heal.Value |
5 | if game.ReplicatedStorage.heal.Value > = 0 then game.ReplicatedStorage.heal.Value = 0 end |
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:
1 | local humanoid = game.Players.LocalPlayer.Character.Humanoid |
4 | humanoid.Health = humanoid.Health + game.ReplicatedStorage.heal.Value |
5 | if game.ReplicatedStorage.heal.Value > = 1 then |
6 | game.ReplicatedStorage.reset:FireServer( 0 ) |
Remote :
1 | game.ReplicatedStorage.reset.OnServerEvent:Connect( function (plr, val) |
2 | game.ReplicatedStorage.heal.Value = val |
Thanks to icodealone#6535 on discord who gave me the answer to my problem and thanks to everyone who tried to help :)