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

How do I make a buy button?

I am trying to make a button that under the conditions that someone doesn't own a car and has enough money, they can clone a car from Lighting and put it at a certain position in Workspace. And then make it so the car owner can't buy anymore cars. Please excuse my Lua as it is complete and utter trash.

What I did was made it so if a player does not own a car their intvalue is 0 and if they do the intvalue is 1. I wasn't sure of a better way to have it. If someone knows a better way I can do it so the game recognizes the car to be owned by a player, please share it! Thanks.

-- setup local variables
local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton
local amount = 500
local carname = game.Lighting.Godzilla
-- when player clicks on buy brick promt him/her to buy a product
buyButton.MouseButton1Click:connect(function()
	if game.Players.LocalPlayer.CarOwner.Value == 0 and if game.Players.LocalPlayer.leaderstats.Money.Value >= amount then
		 game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - amount
		carname:clone() 
		carname.clone.Parent = game.Workspace
		carname.clone.Position = (0,0,0)
		game.Players.LocalPlayer.CarOwner.Value = 1
	else 
	end
end)

2 answers

✓ Accepted answer

I'd recommend setting a variable for the clone, which I did. The way you have it set up with the IntValue is fine. I fixed a few minor issues.

-- setup local variables
local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton
local amount = 500
local carname = game.Lighting.Godzilla
-- when player clicks on buy brick promt him/her to buy a product
buyButton.MouseButton1Click:connect(function()
    if (game.Players.LocalPlayer.CarOwner.Value == 0) and (game.Players.LocalPlayer.leaderstats.Money.Value >= amount) then
         game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - amount
        clo = carname:clone()
        clo.Parent = game.Workspace
        clo:MakeJoints()
        clo:MoveTo(0,0,0) -- Where you want it to be spawned.
        game.Players.LocalPlayer.CarOwner.Value = 1
    end
end)


3 comments

0

Also, the part position doesn't work, it just spawns where the model was before it was put in lighting.

0

I have 2 more things, the part seems to break in pieces then welds.. http://puu.sh/ablnj/98a6348e80.jpg and also how do I make it so the script doesn't break after it is used one time...? I will accept the answer once I get it working how I need it. :)

0

The car only breaks if it was Cframed and has a weld script in it, uncframed cars are fine.

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