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

"PlayerScripts" doesn't exist in players in online mode?

Asked by 6 years ago

So i have a function in a ModuleScript that loops through every player in the game and inserts MapFocus (a local script) into their "PlayerScripts" for camera manipulation:

function _M.InitiateCamera()
    for i, v in ipairs(game.Players:GetChildren()) do
        local MapFocusNew = ServerStorage.MapFocus:Clone()
        MapFocusNew.Parent = v.PlayerScripts
        MapFocusNew.Disabled = false
        wait()
        MapFocusNew:Destroy()
    end
end

And it works nicely in studio, but not in online mode. The error put out online is "PlayerScripts" is not a valid member of Player. So I attempted to add a WaitForChild as shown:

MapFocusNew.Parent = v:WaitForChild("PlayerScripts")

...which resulted in an infinite wait. To truly see if it was there online, I used the f9 console to print my player's PlayerScripts, and other children of my player, and the PlayerScripts was the only one that threw a not-a-valid-member error.

Am I skipping a step, or should I insert the script elsewhere?

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

"Unlike instances such as PlayerGui and Backpack, PlayerScripts are not accessible to the server."

This means that you will need to use a local script in order to access PlayerScripts, as the server can't access it.

Source: http://wiki.roblox.com/index.php?title=API:Class/PlayerScripts

Ad

Answer this question