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

Check if player has item in inventory + remove it?

Hello, i am in the process of making a puzzle game, i need to make players put sticks in a campfire. How would i make it so that, on the clicking of the campfire, a script checks if the player has a stick, and remove it?

thanks

4 comments

0

You can send your script?

0

hasnt been made yet.

0

Then if you haven't made a script, then don't post, you won't get any answers. This isn't a request site.

0

bad questions 101

2 answers

the place where the player stores tools and stuff is called the backpack. With that knowledge we can write up a script which can perform this task. You will place this in the campfire along with a ClickDetector, and your stick will be a tool named "Stick" for this to work, or u can alter it yourself

local campfire = script.Parent
local click_detector = campfire.ClickDetector -- the click detector

local sticks = 0 -- the sticks in campfire

click_detector.MouseClick:connect(function(player)
	
	local inventory = player.Backpack
			
	for i, v in pairs(inventory:GetChildren()) do
		if v:IsA("Tool") and v.Name == "Stick" then -- evaluate if tool is a stick
			v:Destroy()
			
			sticks = sticks + 1
		end
	end
end)
local Campfire = game.Workspace.Campfire -- Where ever it is
local ClickDetector = Campfire.ClickDetector -- Where ever it is

ClickDetector.MouseClick:Connect(function(player)
	local Inventory = player.Inventory -- Where ever players inventory is
	if Inventory:FindFirstChild("Stick") then
		local Stick = Inventory["Stick"]
		local Amount = Stick.Amount -- Number Value Inside Of Stick For Amount Of Sticks Player Has
		if (Amount.Value - 1) <= 0 then
			Stick:Destroy()
			-- Do The Rest
		else
			Amount.Value = Amount.Value - 1
			-- Do The Rest
		end
	end
end)

k.

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