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

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

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.

1 comment

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.

1 answer

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)

4 comments

0

I'll try it out! Thanks! I'll let ya know if it works

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?

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

0

oh also should it be in a seperate script from my cash system script, and if so, where should this script be?

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