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

im confused, why does my code only work in roblox studio and not on a public/private server?

Asked by 6 years ago
Edited 6 years ago
local id = 5010007
    local Script = game.ServerScriptService.GamePassDoubleJump
    local LScript = game.ServerScriptService.GamePassDoubleJump.DoubleJump
    local scriptclone = LScript:clone()
        game.Players.PlayerAdded:connect(function(player)
            if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
                scriptclone.Parent = game.Players.LocalPlayer.PlayerScripts
          end  
    end)

im confused, it only works in studio.

Error: ServerScriptService.GamePassDoubleJump:7:attempt to index field 'LocalPlayer" (a nil value)

0
you can only use LocalPlayer in a localscript, not a server script. Replace 'game.Players.LocalPlayer' with 'player' since the PlayerAdded event already passes a 'player' arguement. hellmatic 1523 — 6y
0
i tried that :/ i will try it again. stumplee555 4 — 6y
0
OHHHH Just player stumplee555 4 — 6y
0
nvm doesnt work stumplee555 4 — 6y

1 answer

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

Ancestry

The top ancestor (excluding the DataModel and the Players service) of a LocalScript is, well, the LocalPlayer. Scripts run on the server, whilst LocalScripts run on the client.

Why LocalPlayer is nil on the server

Think of it as your school classroom. Your desk is your desk, just like how your LocalScript is your LocalScript, it works for you. But your classroom is your classroom, and in it are your classmates as well as your teacher. Think of the classroom as the server. It has everyone in it, and cannot keep track of who in the heck LocalPlayer is! For this reason, LocalPlayer is nil on the server. Code cannot your mind. This is why it must be all typed out. So instead of doing this:

make a part inside of the workspace with color red

You must do this:

local part = Instance.new("Part")
part.BrickColor = BrickColor.new("Really red")
part.Parent = workspace 
0
Sorry for the LocalPlayer tutorial, had to do it, it is too common to use LocalPlayer on the server. User#19524 175 — 6y
0
( ?° ?? ?°)( ?° ?? ?°)( ?° ?? ?°)( ?° ?? ?°)( ?° ?? ?°) User#23365 30 — 6y
0
i tried the code didnt work :/ stumplee555 4 — 6y
0
Make sure it's a Server Script in ServerScriptService User#19524 175 — 6y
View all comments (6 more)
0
Server script i know of a script, local script, and module scripts stumplee555 4 — 6y
0
try cloning it into Backpack see what happens User#19524 175 — 6y
0
K stumplee555 4 — 6y
0
Backpack is not a valid member of Player stumplee555 4 — 6y
0
WaitForChild User#19524 175 — 6y
0
??? stumplee555 4 — 6y
Ad

Answer this question