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
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
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.
4 comments
You can send your script?
hasnt been made yet.
Then if you haven't made a script, then don't post, you won't get any answers. This isn't a request site.
bad questions 101