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

why cant i access ServerStorage with a local script?

Asked by 4 years ago
Edited 4 years ago

my guess is that it's a local script so it cant change/read the values and run an if statement here's the error: pause_and_play_value is not a valid member of ServerStorage|code:

function pause()
    if game.ServerStorage.pause_and_play_value.Value == "playing" then
        game.ServerStorage.pause_and_play_value.Value = "paused"
        while game.ServerStorage.pause_and_play_value.Value == "paused" do
            wait (0.1)
            workspace.MusicScript.S1:Pause()
            workspace.MusicScript.S2:Pause()
            workspace.MusicScript.S3:Pause()
            workspace.MusicScript.S4:Pause()
            workspace.MusicScript.S5:Pause()
            script.Parent.Image = 'http://www.roblox.com/asset/?id=5167333273'
        end
    end
    if game.ServerStorage.pause_and_play_value.Value == "paused" then

    end
end
script.Parent.MouseButton1Click:Connect(pause)

4 answers

Log in to vote
2
Answered by 4 years ago

ServerStorage LocalScript . I already see the problem, but I'll explain it to you anyways. ServerStorage is Server only, while Local Scripts focus on the client. You can either solve this by putting the item in ReplicatedStorage or you can use remote events.

0
oops..sorry LTRNightmare 66 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Local scripts are for... You know. Local. They can’t access other areas expect for the player.

Log in to vote
0
Answered by
VAHMPIN 277 Moderation Voter
4 years ago

Local Scripts are used for the local player, they are usually used to fire off REMOTE EVENTS which could be useful in your case. Make a script which will fire an event to change the on and off value!

https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

Log in to vote
0
Answered by 4 years ago

LocalScript cannot access the ServerStorage, it is only accessable to Script / ServerScripts.

But fortunately, LocalScript can in fact access ReplicatedStorage

So I recommend you moving pause_and_play in ReplicatedStorage

You're code should look like this when you moved it:

function pause()
    if game.ReplicatedStorage.pause_and_play_value.Value == "playing" then
        game.ReplicatedStorage.pause_and_play_value.Value = "paused"
        while game.ReplicatedStorage.pause_and_play_value.Value == "paused" do
            wait (0.1)
            workspace.MusicScript.S1:Pause()
            workspace.MusicScript.S2:Pause()
            workspace.MusicScript.S3:Pause()
            workspace.MusicScript.S4:Pause()
            workspace.MusicScript.S5:Pause()
            script.Parent.Image = 'http://www.roblox.com/asset/?id=5167333273'
        end
    end
    if game.ReplicatedStorage.pause_and_play_value.Value == "paused" then

    end
end
script.Parent.MouseButton1Click:Connect(pause)

Answer this question