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

Can someone fix my buy button script?

Asked by
Seraine 103
10 years ago

I have a house which you can buy in game, the first time you buy it everything works fine. But once you sold the house, it won't let you buy it again for some reason :L

Please help if you can...Thanks !

Buy house script:

owned = script.Parent.Parent.Parent.Owned.Value

script.Parent.Touched:connect(function(hit)
    player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then 
        if owned == false and player.Cash.Value >=1000 and player.HasHouse.Value == false then
            player.Cash.Value = player.Cash.Value - 1000
        clone = game.Lighting.House:clone()
      clone.Parent = player.PlayerGui
            player.HasHouse.Value = true
            player.PlayerGui.House.Frame.House1.Visible = true -- From this line and below are the buttons for the House Gui, it lets you change the settings of the house you bought.
            player.PlayerGui.House.Frame.lockhouse1.Visible = true
            player.PlayerGui.House.Frame.lightson1.Visible = true
            player.PlayerGui.House.Frame.curtainsclose1.Visible = true
            player.PlayerGui.House.Frame.bathroom1.Visible = true
            player.PlayerGui.House.Frame.kitchen1.Visible = true
            player.PlayerGui.House.Frame.bedroom1.Visible = true
            script.Parent.Parent.Parent.Owned.Value = true
            script.Parent.Parent.Parent.OwnedBy.Value = player.Name
script.Parent.Parent:remove()
        else
        print("Not enough to purchase house.")  
        end
    end
end)


Sell house script:

function Click(mouse)
plr=script.Parent.Parent.Parent.Parent.Parent

            game.Workspace.Housee1:remove() -- Housee1 is the name of House, since the house Gui and the House building is both named House(num) and both inside Lighting, I decided to name the building different.
        clone = game.Lighting.Housee1:clone()

            clone.Parent = game.Workspace
game.Workspace.Kitchen:remove()
game.Workspace.Bedroom:remove()
game.Workspace.Bathroom:remove()
game.Workspace.LivingRoom:remove()

         plr.Cash.Value = plr.Cash.Value+500
plr.PlayerGui.House:remove()
plr.HasHouse.Value = false




end

script.Parent.MouseButton1Down:connect(Click)

I use a Gui for in game currency by the way, not a leaderboard.

0
12 Hours still no answer? Seraine 103 — 10y

2 answers

Log in to vote
0
Answered by
TofuBytes 500 Moderation Voter
10 years ago

Well, I was searching through and I noticed that Bedroom, Bathroom, and LivingRoom are all inside of the workspace, instead of a certain model. If there are none of those inside the Workspace, then the script will not completely execute.

function Click(mouse)
plr=game.Players.LocalPlayer --This was also changed because it's a client mouse click.

            game.Workspace.Housee1:remove()
        clone = game.Lighting.Housee1:clone()

            clone.Parent = game.Workspace
    game.Workspace.Kitchen:remove() --These should be placed into the specific house
game.Workspace.Bedroom:remove() --
game.Workspace.Bathroom:remove() --
game.Workspace.LivingRoom:remove() --


plr.Cash.Value = plr.Cash.Value+500
plr.PlayerGui.House:remove()
plr.HasHouse.Value = false
end

script.Parent.MouseButton1Down:connect(Click)
Ad
Log in to vote
-1
Answered by
wrenzh 65
10 years ago

In the Sell Script on line 15, you wrote plr.PlayerGui.House:remove(), and then in the Buy Script on line 11 you wrote player.PlayerGui.House.Frame.House1.Visible = true.

I suggest you don't destroy the GUI when the player sells the house so that they can buy a house again.

0
Sell house script: plr=script.Parent.Parent.Parent.Parent.Parent Seraine 103 — 10y

Answer this question