Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

4 comments

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.

0

i tried that :/ i will try it again.

0

OHHHH Just player

0

nvm doesnt work

1 answer

#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 

10 comments

0

Sorry for the LocalPlayer tutorial, had to do it, it is too common to use LocalPlayer on the server.

0

( ?° ?? ?°)( ?° ?? ?°)( ?° ?? ?°)( ?° ?? ?°)( ?° ?? ?°)

0

i tried the code didnt work :/

0

Make sure it's a Server Script in ServerScriptService

0

Server script i know of a script, local script, and module scripts

0

try cloning it into Backpack see what happens

0

K

0

Backpack is not a valid member of Player

0

WaitForChild

0

???

This discussion is preserved as it was. New answers, comments, and votes are closed.