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

Help me on this script?

Asked by 10 years ago

I am making a town/city game, and I am currently working on the neighborhood, and I am not a good scripter. I built a house but I have a script that tells you how much money you have. But when you buy the house you spend some money. You start off automatically with 1000 dollars. But each house will cost 300 dollars. Here is the script I have so far but I don't think it is correct please help me

function moneyvalue(player)
    local stats = Instance.new("IntValue")
    stats.Name = "Leaderstats"
    local c = Instance.new("IntValue")
    c.name = "Money"
    c.value = 300
    c.parent = stats
    stats.parent = player
    newPlayer.Change:connect (function (property)
        end)
    end

    game.Players.ChildAdded:connect (Playerboughthouse)

Thank you, Tristen126

2 answers

Log in to vote
0
Answered by
samfun123 235 Moderation Voter
10 years ago

After reading this I'm assuming that you want players to spawn with 1000 dollars and want to be able to deduct money. I can't really help with the buying of house part but I can help with the deducting.

function moneyvalue(player) -- Cleaned up this code alittle
    local stats = Instance.new("IntValue",player)
    stats.Name = "leaderstats"
    local c = Instance.new("IntValue",stats)
    c.Name = "Money"
    c.Value = 1000 -- Starter amount of money
end

function deductmoney(player,amount)
    if player and amount then -- Make sure you passed a player and the amount
        plr = game:GetService("Players"):FindFirstChild(player) -- Get the player
        if plr and plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Money") then -- Make sure they have stats and they are here
            if plr.leaderstats.Money.Value >= amount then
                plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - amount
                return true
            else
                return false
            end
        end
    end
end

game.Players.ChildAdded:connect(moneyvalue)

To remove money from a player all you have to do its run the deductmoney function with the player name and how much to remove. Example :

deductmoney("samfun123",300)

The function will also return true if it deducted money, if the player doesn't have enough money it will returns false.

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

Ad
Log in to vote
-1
Answered by 10 years ago

Test it out first, then return a reply with what errors are there.

0
I tested it, it worked I am just now confused how to use it e.o TristenBlack 25 — 10y

Answer this question