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

Help Stop from buying multiple???

Asked by 5 years ago

how do i make it so that once you buy a house you cannot buy another? what code would i use and where would i put it??? i need help im such a confused noob thanks so much :P

local house = script.Parent.Parent
local houseprice = house:WaitForChild("Price")
local currentowner = house:WaitForChild("CurrentOwner")
local ClickDetector = script.Parent:WaitForChild("ClickDetector")

ClickDetector.MouseClick:Connect(function(player)
    if player:FindFirstChild("leaderstats") and currentowner.Value == "" then
        local SC = player.leaderstats:FindFirstChild("SC")
        -- We know that the player has leaderstats
        if SC and SC.Value >= houseprice.Value then
            house.Name = player.Name.."'s House"
            SC.Value = SC.Value - houseprice.Value
            currentowner.Value = player.Name
        end
    end
end)

0
Don't delete and repost your question if it's been 2 hours... Shawnyg 4330 — 5y
0
sorry, didn't know the rules im new TacoBellPowderedBeef 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

My best fix to this issue is putting a "BoolValue" in the player. When it's checked it can mean that the player has a house. You can use an "if" statement in your script to check if it's false to allow the player to buy the house. Something like the following from your code:

if player:FindFirstChild("leaderstats") and currentowner.Value == "" and player:FindFirstChild("OwnsHouse").Value ~= true then
    --Your other code (insert something that changes the value to false "player:FindFirstChild("OwnsHouse").Value = false")
end

If you have any questions or issues, please contact me. ;)

0
@lazycoolboy500 where do i put this script? Thanks so much!!!!! TacoBellPowderedBeef 0 — 5y
0
also --your other code (insert something...) wdym by that? TacoBellPowderedBeef 0 — 5y
0
or you could put the houses in a table, ex: { ["House1"] = {obj = game.Workspace["House1"], owner = nil} } bhqpping 80 — 5y
0
watchu mean TacoBellPowderedBeef 0 — 5y
View all comments (6 more)
0
im so lost lmao TacoBellPowderedBeef 0 — 5y
0
You can leave your script where it is considering that you can already get the player with your script. Just keep reading everything that I posted and you should be fine. lazycoolboy500 597 — 5y
0
hmu ThesePloits#5897 a4aw -5 — 5y
0
lazycoolboy500, i put the script you gave me in my script but now it prevents me from buying it, is there a specific spot i put it or change it in any way? TacoBellPowderedBeef 0 — 5y
0
19:16:08.374 - Workspace.Skinny Home.Door.BuyHouseScript:16: ')' expected near 'OwnsHouse' TacoBellPowderedBeef 0 — 5y
0
thats the error i get TacoBellPowderedBeef 0 — 5y
Ad

Answer this question