So I have two scripts, one to harvest the item and one for the inventory system. The inventory system has to press 'F' to collect and then 'Click' to harvest. I just want to merge the two to work together here's the first one:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
repeat wait() until Player.Character wait()
local Mouse = Player:GetMouse()
local Camera = game.Workspace.CurrentCamera
local promptHint = Player.PlayerGui:WaitForChild("ScreenGui").prompt
local promptHintTwo = Player.PlayerGui.ScreenGui.prompt2
local currentInventory = Player.PlayerGui.ScreenGui.currentInventory
local currentInventoryTitle = Player.PlayerGui.ScreenGui.currentInventoryTitle
local currentInventoryCurrentCapacity = Player.PlayerGui.ScreenGui.currentInventoryCurrentCapacity
local currentInventoryMaxCapacity = Player.PlayerGui.ScreenGui.currentInventoryMaxCapacity
--"distance" player needs to be inside to see prompt to pick up item
local magnitudeNearItem = 10
--local max capacity player can carry
local carryWeight = 10
--amount of capacity currently player has
local currentWeight = 0
--Creating a player's inventory
local playerInventory = Instance.new("Folder")
playerInventory.Parent = ReplicatedStorage
playerInventory.Name = Player.Name.."'s Inventory"
--Detecting if a player's mouse is hovering over a pickable object. If they are, then show promptHint.
UserInputService.InputChanged:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement and Mouse.Target ~= nil and Mouse.Target:FindFirstChild("isPickable").Value == 1 and((Player.Character.Torso.Position - Mouse.Target.Position).magnitude)<magnitudeNearItem then
promptHint.Visible = true
promptHint.Text = "PRESS 'F' TO PICK UP"
else
promptHint.Visible = false
end
end)
UserInputService.InputBegan:Connect(function(input,GPE)
--If key is "F", then put item into player's inventory.
if input.KeyCode == Enum.KeyCode.F and Mouse.Target ~= nil and Mouse.Target:FindFirstChild("isPickable") and((Player.Character.Torso.Position - Mouse.Target.Position).magnitude)<magnitudeNearItem and not GPE then
--Gets data from modulescript from item
local itemData = require(Mouse.Target.itemSettings)
--if its possible to carry then add to inventory, else prompt saying can't carry anymore
if (currentWeight+itemData.weight) <= carryWeight then
currentWeight = currentWeight + itemData.weight
Mouse.Target.Parent = playerInventory
else
spawn(function()
promptHintTwo.Visible = true
promptHintTwo.Text = "CANNOT CARRY ANY MORE ITEMS"
wait(1)
promptHintTwo.Visible = false
end)
end
--If key is "G", then list all items in inventory in output.
else if input.KeyCode == Enum.KeyCode.G and not GPE then
local inventoryChildren = playerInventory:GetChildren()
local inventoryString = ""
for i=1, #inventoryChildren do
--Gets data from modulescript from item
local itemData = require(inventoryChildren[i].itemSettings)
inventoryString = inventoryString..itemData.name..", "
end
currentInventoryTitle.Visible = true
currentInventory.Visible = true
currentInventory.Text = inventoryString
currentInventoryCurrentCapacity.Visible = true
currentInventoryCurrentCapacity.Text = "CURRENT CAPACITY: "..currentWeight
currentInventoryMaxCapacity.Visible = true
currentInventoryMaxCapacity.Text = "MAXIMUM CAPACITY: "..carryWeight
--If key is "E", then empty out all inventory back into game. Objects are positioned in direction player is facing, and larger objects are placed farther away.
else if input.KeyCode == Enum.KeyCode.E and not GPE then
local inventoryChildren = playerInventory:GetChildren()
for i=1, #inventoryChildren do
inventoryChildren[i].Parent = workspace
inventoryChildren[i].CFrame = Player.Character.Torso.CFrame + (Player.Character.Torso.CFrame.lookVector * inventoryChildren[i].Size)
wait()
end
--remove item from inventory currentWeight = currentWeight - itemLeaving.weight. since this just removes all items: currenWeight is set to 0
currentWeight = 0
end
end
end
end)
UserInputService.InputEnded:Connect(function(input,GPE)
--If player lets go of "G", then take off GUIs.
if input.KeyCode == Enum.KeyCode.G and not GPE then
currentInventoryTitle.Visible = false
currentInventory.Visible = false
currentInventoryCurrentCapacity.Visible = false
currentInventoryMaxCapacity.Visible = false
end
end)
--If player dies, remove all items in inventory
Player.Character.Humanoid.Died:Connect(function()
playerInventory:ClearAllChildren()
end)
and the second:
local model = script.Parent.Parent
local brick = script.Parent
local gui = brick.BillboardGui
local click = brick.ClickDetector
local text = gui.TextBox
local scroll = gui.Scroll
local click = script.Parent.ClickDetector
local branches = script.Parent.Parent.branches:GetChildren()
local isPickable = brick.isPickable
scroll.Size = (UDim2.new(0,5,0,5))
val = 0
local function onMouseClick(player)
text.Text = "Harvesting..."
repeat
val = val + 1
scroll.Size = (UDim2.new(val, 5, 0, 5))
wait(3)
if val>=1 then
break
end
until val==1
text.Text = "Harvested!"
isPickable = 1
brick.Transparency = 1
brick.CanCollide = false
scroll.Size = (UDim2.new(0,5,0,5))
wait(1) -- Split
for i = 0.1, 1, 0.1 do
for i,v in pairs(branches) do
v.Transparency = i
end
wait(0.1)
model:Destroy()
print("killed")
end
end
click.MouseClick:connect(onMouseClick)
