Players.deathmatch7540.PlayerGui.PurchaseCar.Yes - $5,000.LocalScript:11: attempt to index local 'leader' (a nil value)
I'm currently trying to make a purchase/spawn button for a vehicle, except the above error message keeps popping up. I tried adding WaitForChild("leaderstats") and other such variations to no success. Help with this would be greatly appreciated!
Deathmatch7540
local button = script.Parent
local function onButtonActivated(player)
local plr = player.name
local leader = plr.leaderstats
local price = script.Parent.Parent.Price.Value
local car = workspace.CarsInGame:FindFirstChild(plr)
if leader.Cash.Value >= price then
leader.Cash.Value = leader.Cash.Value - price
if car then
car:Destroy()
local clone = game.ReplicatedStorage.Cars.ArmyTruck:clone()
clone.Parent = game.Workspace.CarsInGame
clone.Name = plr
else
local clone = game.ReplicatedStorage.Cars.ArmyTruck:clone()
clone.Parent = game.Workspace.CarsInGame
clone.Name = plr
end
end
script.Parent.Parent:Destroy()
end
button.Activated:Connect(onButtonActivated)

1 comment
Alright, thank you! I do believe it worked because I am no longer getting the error message. I just have to fix all the other stuff that I messed with!