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

Why won't this work?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)"

0
Where are you using the variable `player` that you set in the server script? BlueTaslem 18071 — 9y
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. BlueTaslem 18071 — 9y
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 NAWESOME14 40 — 9y
0
What are you trying to make that requires this? Perci1 4988 — 9y
View all comments (3 more)
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? NAWESOME14 40 — 9y
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? TheeDeathCaster 2368 — 9y
0
Ok, I'll do that. Thank you guys for dealing with my noobness... NAWESOME14 40 — 9y

1 answer

Log in to vote
0
Answered by
Moxeh 84
9 years ago

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
0
I tried that too... I can't seem to refrence the player after I set the value, to object value NAWESOME14 40 — 9y
Ad

Answer this question