Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Car dealership "purchase button"?

****so i am trying to make this car dealership where if you click on a block thats infront of a car, a menu pops up (that works, here is a screenshot: https://imgur.com/NjUaJaT) with some info and a picture of the car. but i tried different types of scripts for the "purchase button" and none work. (i got this from another post because i am too dumb for this)

this is the one i have right now:

01	player = script.Parent.Parent.Parent.Parent.Parent
02	cost = 5000
03	 
04	script.Parent.MouseButton1Click:connect(function()
05	     leaderstats = player:FindFirstChild("leaderstats")
06	    if leaderstats then
07	         money = leaderstats:FindFirstChild("Money")
08	        if money then
09	            if money.Value >= cost then
10	                spawncar = game.Lighting:FindFirstChild("CiviCar"):clone() --Use FindFirstChild or WaitForChild instead.
11	        local weld = Instance.new("Weld", spawncar.Seat) --Change this to any part in the car with a unique name. If your car already has welds, remove this line!
12	                spawncar.Parent = workspace
13	                spawncar:MakeJoints() --You need welds to actually use :MakeJoints(). MakeJoints is a function! Use ":" instead of "." like as if it's a property!
14	                player.leaderstats.Money.Value = player.leaderstats.Money.Value - 5000
15	                script.Parent.Text = "Bought"
16	                else
17	                script.Parent.FontSize = 14
18	                script.Parent.Text = "Not enough $"
19	                return
20	            end
21	        end
22	    end
23	end)


2 answers

Did you include the numbers in the script? If you did, get rid of the numbers.

The thing that is wrong with your script is most likely your definition of the player. You define the player as:

player = script.Parent.Parent.Parent.Parent.Parent

I can obviously not see your "tree", but that is most likely wrong. If you have a wrong definition of the player, you will not be able to FindFirstChild("leaderstats"). This will then break your script.

If you're using a local script, simply locate the player by doing:

local player = game:GetService("Players").LocalPlayer

You're also using script.Parent.MouseButton1Click:connect(function(). You should use Connect, (with a capital C). The old version is deprecated.

1 comment

0

i am super noob at this stuff (like i said in the post) but it didn't work, and i have no clue if i have to add the localscript to the textbutton or not. what i changed made more warnings. i will provide a screenshot in another answer if you need it

This discussion is preserved as it was. New answers, comments, and votes are closed.