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:

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 -- The actuall value
14:11:56.591  LocalScript thinks that heal.Value = 0  -  Client - LocalScript:6 -- doesnt see the new value

applePickupScript

script.Parent.Touched:Connect(function(hit)

    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players[hit.Parent.Name]
        local audio

        if script.Parent.AppleQuality.Value == 1 then
            audio = hit.Parent.Head.audio1
        else
            audio = hit.Parent.Head.audio2
        end

        player.leaderstats.Apples.Value = player.leaderstats.Apples.Value + script.Parent.AppleQuality.Value
        audio:Play()

        for i, v in pairs(workspace.spawnLocations:GetChildren()) do
            if v.Position == script.Parent.Position then
                v.spotTaken.Value = false
                v.garga.Value = true
            else
                v.garga.Value = false
            end
        end

        game.ReplicatedStorage.heal.Value = 20 -- Updates the value
        script.Parent:Destroy()

    end

end)

LocalScript

local humanoid = game.Players.LocalPlayer.Character.Humanoid

while wait() do
    humanoid.Health = humanoid.Health + game.ReplicatedStorage.heal.Value
    if game.ReplicatedStorage.heal.Value >= 0 then game.ReplicatedStorage.heal.Value = 0 end
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:

local humanoid = game.Players.LocalPlayer.Character.Humanoid

while wait() do
    humanoid.Health = humanoid.Health + game.ReplicatedStorage.heal.Value
    if game.ReplicatedStorage.heal.Value >= 1 then
        game.ReplicatedStorage.reset:FireServer(0)
    end
end

Remote :

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

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