Error on find Player

I made a car Purchase system in my game, the script is in ServerScriptService. Im getting this error on the first line: Argument 1 missing or nil - Server - PurchaseScript:4
I dont know how to fix this, i appreciate if anyone could help me fix it.



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)

Argument 1 is supposed to be a string for the name so FindFirstChild returns the first child of the Instance found with the given name.

Also player is defined twice:

So which one should i remove then?

depends how you want to find the player mate but this one is the issue as you havent enter argument 1

The first one cuz it’s not gonna work

You have player defined twice, you should remove the first one, and replace the second one with script:FindFirstAncestorOfClass("Player").

Why 2 local player the script can only define 1 per script or function so the first one won’t work cuz FindFirstChild is empty and it have to be written player name, if you wrote your username others script won’t work so keep doing in the player below and remove the first one

Bro you made the player a character :skull:

Pardon? Who are you replying too…

Edit: My code ?I wrote was wrong :stuck_out_tongue:

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