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

Why does this script work perfectly in Studio but does not work in game?

Asked by
SuperFryX 130
8 years ago

In studio, this function works absolutely fine. But in game, it gives an error saying PlayerScripts is not a valid member of Player, which is really confusing since PlayerScripts is clearly there in Studio mode.

function bindToNewPlayer()
    vPlayer = game.Players:GetPlayerFromCharacter(vChar)
    if vPlayer then
        print ((vPlayer.Name).." Has entered!")
        local CLocalScript=LocalScript:clone()
        CLocalScript.Parent=vPlayer.PlayerScripts-------This is the line that is causing errors.
    end
end

1 answer

Log in to vote
1
Answered by 8 years ago

**Problem **

The only problem I can see is that since it works in studio and not in server it should be a latency problem, this happens because in studio everything is pretty much local so you don't have to wait for a server to create stuff so your local scripts run instantly. In server this doesn't happen as when a local scripts cause upons something in player or character that is server-sided then the local script is "local" which makes it run faster then the server can respond.

Solution

repeat wait() until game.Players.LocalPlayer.Character--To the top of every local script
Ad

Answer this question