The Money line doesnt work im getting an error in the output.
--Config
local player = game.Players:findFirstChild()
local price = 15000 --Change to price of vehicle
local CarName = "Beige Dune Buggy" --Change to vehicle name
--Do not edit past this
local player = script.Parent.Parent.Parent.Parent.Parent
local Money = player.leaderstats.Money
script.Parent.Parent.Parent.Name = CarName
local BuyTitle = script.Parent.Parent.TextLabel
BuyTitle.Text = "Would you like to buy " .. CarName .. " for " .. price --This automaticly changes the GUI to show the name of the vehicle and the price!
script.Parent.MouseButton1Click:Connect(function()
if Money.Value >= price and player[CarName][CarName].Value == 0 then--If the player has enough money and does not own the vehicle
Money.Value = Money.Value - price--Takes the money
player[CarName][CarName].Value = 2
wait()
script.Parent.Parent.Parent.Enabled = false
elseif Money.Value <= price and player[CarName][CarName].Value == 0 then
BuyTitle.TextColor3 = Color3.new(1, 0, 0.0156863)
wait(0.3)
BuyTitle.TextColor3 = Color3.fromRGB(150, 150, 150)
--BuyTitle.TextColor3 = Color3.new(150, 150, 150)
end
end)
It is because your player value is nil, nil basically means it was not assigned, and that is what is causing the error. That leads me to believe that the script is not located in a place where the player is script.Parent.Parent.Parent.Parent.Parent
local player = game.Players:FindFirstChild() needs to require an argument, for example; local player = game.Players:FindFirstChild("IAmTailerr")
Also make sure you capitalize the f on Find in your code.
If this is running in a localscript you can use local player = game.Players.LocalPlayer, however editing money from a local side shouldnât be done and should be done server side.
First things first I would HIGHLY recommend transferring that script into a local script because then you can just state, local player = game.Players.LocalPlayer
Exactly this, and then using a RemoteEvent to do messages between the server to remove their money, otherwise the server wonât see this, leaderstats wonât update server-side and datasaving wont work.
local player = game.Players.LocalPlayer
local gui = script.Parent.Parent.Parent
local price = 15000 --Change to price of vehicle
local CarName = "Beige Dune Buggy" --Change to vehicle name
local Money = player:WaitForChild("leaderstats").Money
gui.Name = CarName
local BuyTitle = script.Parent.Parent.TextLabel
BuyTitle.Text = "Would you like to buy " .. CarName .. " for " .. price --This automaticly changes the GUI to show the name of the vehicle and the price!
script.Parent.MouseButton1Click:Connect(function()
if Money.Value >= price and player[CarName][CarName].Value == 0 then--If the player has enough money and does not own the vehicle
game.ReplicatedStorage.RemoteEvent:FireServer(price, CarName)
wait()
script.Parent.Parent.Parent.Enabled = false
elseif Money.Value <= price and player[CarName][CarName].Value == 0 then
BuyTitle.TextColor3 = Color3.new(1, 0, 0.0156863)
wait(0.3)
BuyTitle.TextColor3 = Color3.fromRGB(150, 150, 150)
--BuyTitle.TextColor3 = Color3.new(150, 150, 150)
end
end)
Not only that, but it when somebody purchases an item, it will purchase for the entire server. @dav2777 you should definitely be using a LocalScript in this situation.