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

Why won't this work?

So, I put an object value into workspace,named it "player", wrote a local script that said this in it:

wait()
game.Workspace.player.Value=game.Players.LocalPlayer
script:Destroy()
--this is to identify a local player, in a server script

and then I wrote a server script that gets that value:

game.Workspace.player.Changed:connect(function(value)
player=value
end)
--this connects the value in the object value I made earlier, to the local player

I get this as a result:

"attempt to index global 'player' (a nil value)"

7 comments

0

Where are you using the variable player that you set in the server script?

0

Better question: Why are you doing this? There can be more than one player in a server. If you want to know when they spawn, use CharacterAdded.

0

I set the variable 'player' under the second function. What I am basically attempting is to refrence a local player, so that I can use it in a Script, instead of a Local Script

0

What are you trying to make that requires this?

0

I'm trying to make a blackjack table, so that players can have money, and chips. And it saves that to each individual player. Does that make sense?

0

Why aren't you using the 'PlayerAdded' event instead of going through all that? Making a function that defines the Player, then the 'PlayerAdded' even to call the function which will define the Player?

0

Ok, I'll do that. Thank you guys for dealing with my noobness...

1 answer

You either had the LocalScript parented wrong, or the missing local inlocal player = value in the Script broke it. Works for me

LocalScript inside StarterGui:

wait()
game.Workspace.player.Value=game.Players.LocalPlayer
script:Destroy()
--this is to identify a local player, in a server script

Script inside ServerScriptService:

game.Workspace.player.Changed:connect(function(value)
local player = value
end)
--this connects the value in the object value I made earlier, to the local player

1 comment

0

I tried that too... I can't seem to refrence the player after I set the value, to object value

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