Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a buy button?

Asked by 10 years ago

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

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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)


0
Also, the part position doesn't work, it just spawns where the model was before it was put in lighting. Champion121212 22 — 10y
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. :) Champion121212 22 — 10y
0
The car only breaks if it was Cframed and has a weld script in it, uncframed cars are fine. Champion121212 22 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Shawnyg

Answer this question