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

I'm trying to make a purchasable door and I can't get it to remove money?

Asked by 1 year ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

I've been able to get everything to work except the money being deducted from your wallet I buy the door and it makes me the owner but takes no money. Any help is very appreciated!!

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"
        else
            local ReplicatedStorage = game:GetService("ReplicatedStorage")
            local DataFolder = ReplicatedStorage:WaitForChild("Data")
            local userObject = DataFolder:FindFirstChild(Player.Name)
            if userObject then
                local walletValue = userObject:FindFirstChild("Wallet").Value
                if walletValue >= 5000 then
                    walletValue = walletValue - 5000
                    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
chomboghai 2044 Moderation Voter Community Moderator
1 year ago

So the issue here is that you have only updated the local wallet value, but have not actually applied the change to the Wallet value object.

What you have:

walletValue = walletValue - 5000 -- This only updates the local variable "walletValue"

You want to update the .Value property of the "Wallet" object in userObject:

local wallet = userObject:FindFirstChild("Wallet") -- Get the wallet object so we can update it later
if wallet.Value >= 5000 then
    wallet.Value = wallet.Value - 5000 -- Notice here that I'm updating the .Value property of the Wallet object

Hope that helps.

0
completely correct. mono67890 -2 — 1y
Ad

Answer this question