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

How to I edit inventory contents through scripts in my game?

Asked by 6 years ago

The game is basically an amusement park game. I have 2 currencies in my game, cash and tickets. Essentially start with cash, buy tickets for the rides, earn more cash through the rides and games to buy more tickets, etc. [it's a friend's idea but I'm curious as to how the gameplay will turn out]

So I have the leaderboard tracking the player's cash and tickets, and I decided it'd be fun to have the player use the cash and tickets as a tool. My issue is I don't want the player to hold up a ticket when they don't have one, and same going for cash.

Essentially, what is the actual code for if(Player.stat.Cash > 0) Player.BackPack.Money = true else Player.BackPack.Money = false end if(Player.stat.tix > 0) Player.BackPack.Tickets = true else Player.BackPack.Tickets = false end

Goal: If player has money, player may hold up and use money tool; if player has tickets, player may hold up and use ticket tool; if player has no money nor tickets, they do not have those tools available.

0
By the way I am new to studio and loua. Yes I read the backpack wiki but it was not too helpful for my particular situation, at least not by my understanding. If it really is explained in the wiki, I will need an explanation of their explanation. DeadSlayer54 0 — 6y

1 answer

Log in to vote
0
Answered by
Arystov 45
6 years ago

Here is an idea of what to do.

script.Parent.Equipped:Connect(function() -- Detect when the tool is equipped.
    if player.Stat.Cash.Value <= 0 then -- Detects if the cash is 0 or lower.
        script.Parent.Parent = player.Backpack; -- If it is, then put the tool back in the backpack.
    end
end)
0
I'll try it out! Thanks! I'll let ya know if it works DeadSlayer54 0 — 6y
0
Didn't work but most likely from an error of my own. Where do I have the tools to start with? Server storage, starter pack? DeadSlayer54 0 — 6y
0
My cash system script is: local function playerentered(newplr) local stat = Instance.new("IntValue") stat.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "Cash" --name of cash/points cash.Value = 10 --starting cash/points cash.Parent = stat local Tix = Instance.new("IntValue") Tix.Name = "Tickets" --name of cash/points Tix.Value = 10 --starting cash/point DeadSlayer54 0 — 6y
0
oh also should it be in a seperate script from my cash system script, and if so, where should this script be? DeadSlayer54 0 — 6y
Ad

Answer this question