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

Can someone help me make it so players can only buy one house?

Asked by 1 year ago
Edited 1 year ago

I tried to add a "rig" value to a player when they purchase a house but it didn't seem to work I thought maybe the debounce was the problem but I changed it and nothing. Thank you for any help!!

``local ting = 0 --debouncer owner = script.Parent.Parent.Parent.OwnerName --This is the thing that holds the owners name

function OnPrompt(Player) if ting == 0 then --debounce check ting = 1 --activate debounce local check = Player.Character:FindFirstChild("Humanoid") --Find the human that touched the button

    if check ~= nil then --If a human is found, then
        local user = game.Players:GetPlayerFromCharacter(Player) --Find human among the players
        local Data = game.ReplicatedStorage.Data:FindFirstChild(Player.Name)

        if Player:FindFirstChild("rig") then 
            script.Parent.ProximityPrompt.ActionText.Text = "You already own a house" --Put text into the message
            wait(3) --Wait to let the message display for a while
            script.Parent.ProximityPrompt.ActionText.Text = "Claim House"
            ting = 0 --remove debounce
            return --exit the function
        else
            local ReplicatedStorage = game:GetService("ReplicatedStorage")
            local DataFolder = ReplicatedStorage:WaitForChild("Data")
            local userObject = DataFolder:FindFirstChild(Player.Name)
            if userObject then
                local walletValue = userObject.Wallet.Value
                if walletValue >= 5000 then
                    walletValue = walletValue - 5000
                    DataFolder:FindFirstChild(Player.Name).Wallet.Value = walletValue
                    owner.Value = Player.Name --save new owners name for later.
                    local own = Instance.new("IntValue")
                    own.Name = "rig"
                    own.Parent = user
                    script.Parent.ProximityPrompt.ActionText = "You now own this house!" --Put text into the message
                    script.Parent.Purchased:Play()
                    wait(1)
                    script.Parent.ProximityPrompt.Enabled =
                        false
                else
                    script.Parent.ProximityPrompt.ActionText = "You don't have enough money to buy this house!"
                    wait(3)
                    script.Parent.ProximityPrompt.ActionText = "Claim House"
                end
            end
        end
    end

    ting = 0 --remove debounce
end

end

script.Parent.ProximityPrompt.Triggered:connect(OnPrompt) --Start listening for button-touchers.``

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

Best idea would to have a owned house value. Example you could use in script is

if player.Housevalue == "" then
--here is where you can allow the player to claim house

Hope this helps!!

Ad

Answer this question