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

Locate Player in a Server Script?

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)

2 comments

0

Error is:

0

Workspace.Mines.Mine2.Collect.GuiPart.SurfaceGui.Frame.TextButton.Script:4: attempt to index local 'player' (a nil value)

1 answer

✓ Accepted answer

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

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