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

Locate Player in a Server Script?

Asked by 8 years ago

How do I locate a player in a Server Script, and get this to work?

script.Parent.MouseButton1Click:connect(function(player)
    script.Parent.Parent.Parent.Parent.Parent.Parent.Collect.MoneyValue.Value = 0
script.Parent.TextLabel.Text ="Money:"..script.Parent.Parent.Parent.Parent.Parent.MoneyValue.Value
    local stats = player:FindFirstChild("leaderstats")
    stats.Money.Value = stats.Money.Value + script.Parent.Parent.Parent.Parent.MoneyValue.Value
end)
0
Error is: HighValue 40 — 8y
0
Workspace.Mines.Mine2.Collect.GuiPart.SurfaceGui.Frame.TextButton.Script:4: attempt to index local 'player' (a nil value) HighValue 40 — 8y

1 answer

Log in to vote
0
Answered by
TrollD3 105
8 years ago

I switched its order so its should work fine now. YOu kept changing the value to zero before anything could be done to it.

local collect = script.Parent.Parent.Parent.Parent.Parent.Parent.Collect
local gui     = script.Parent
script.Parent.MouseClick:connect(function(player)

local stats = player:FindFirstChild("leaderstats")
gui.TextLabel.Text = "Money: "..collect.MoneyValue.Value
 stats.Money.Value = stats.Money.Value + collect.MoneyValue.Value
collect.MoneyValue.Value = 0
end)

To reference a player in server script (im not sure this is the best way but it works regardless)

wait(1)
for _,v in pairs (game.Players:GetChildren()) do
    print(v.Name) --would print your name

end
Ad

Answer this question