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