Trouble with Referencing Player

I am trying to reference the player in this script, it’s a server script, and it’s saying that its trying to index leaderstats with nil, which I suspect it’s because it cannot find the player. How do I fix this?

local player = game.Players.LocalPlayer
local textlabel = script.Parent.Billboard.BillboardGui.RentFrame.TextLabel
local clickpart = script.Parent.ClickPart
local money = player.leaderstats.Money
rented = false
rentprice = 150

clickpart.ClickDetector.MouseClick:Connect(function(player)
	if rented == false and money.Value >= rentprice then
		textlabel.Text = player.Name
		money.Value = money.Value - rentprice
		rented = true
	end
end)
1 Like

You do know that player as the variable exist twice and you can’t get the localplayer inside a server script, you can remove the player variable (first line) and move the money variable inside the function, because there player is referenced.

1 Like

You can’t use LocalPlayer on Server Script. Do this:

local textlabel = script.Parent.Billboard.BillboardGui.RentFrame.TextLabel
local clickpart = script.Parent.ClickPart
local rented = false -- sort something out 
clickpart.ClickDetector.MouseClick:Connect(function(player)
        local money = player.leaderstats.Money
        rentprice = 150
	if rented == false and money.Value >= rentprice then
		textlabel.Text = player.Name
		money.Value = money.Value - rentprice
		rented = true
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.