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

Help Stop from buying multiple???

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)

2 comments

0

Don't delete and repost your question if it's been 2 hours...

0

sorry, didn't know the rules im new

1 answer

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. ;)

10 comments

0

@lazycoolboy500 where do i put this script? Thanks so much!!!!!

0

also --your other code (insert something...) wdym by that?

0

or you could put the houses in a table, ex: { ["House1"] = {obj = game.Workspace["House1"], owner = nil} }

0

watchu mean

0

im so lost lmao

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.

0

hmu ThesePloits#5897

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?

0

19:16:08.374 - Workspace.Skinny Home.Door.BuyHouseScript:16: ')' expected near 'OwnsHouse'

0

thats the error i get

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