I have a game where you can mine stone rocks and it gives you stones, but the giveing stones doesn't work
Here is the main code:
local Stone = script.Parent local MaxHealth = 100 local PickUpItem = require(game.ServerScriptService.ManageItems) local PlaneAxe = game.Workspace["Tactical Axe"] local IsAxe = false local PlaneAxeDmg = 10 local stones = game.Workspace.Items.Resources:FindFirstChild("Stones") local CD = Stone:FindFirstChild("ClickDetector") local Stones = Stone.StoneAmount.Value local damageDone = 0 local humanoid = Stone:FindFirstChildWhichIsA("Humanoid") print("Test") CD.MouseClick:Connect(function(player) if Stone:FindFirstChild("Humanoid") then print("Humnaoid yes!") if IsAxe == true then print("Hit by an axe") local CurrentHealth = humanoid.Health local newHealth = CurrentHealth - PlaneAxeDmg humanoid.Health = newHealth damageDone += PlaneAxeDmg local amount1 = Stones - damageDone for hit = 1, damageDone do -- for each hit a player has done to stone node if not humanoid.Died then PickUpItem.PickUpItem(stones, amount1, player) -- Pick up item, ItemAmount and give to the player if amount1 == 0 then return end end end if humanoid.Health == 0 then damageDone = 0 Stone.HasMined.Value = true PickUpItem.PickUpItem(stones, amount1, player) humanoid:Destroy() --PickUpItem.PickUpItem(stones, 1, player) end end else return end end) PlaneAxe.Equipped:Connect(function() IsAxe = true end) PlaneAxe.Unequipped:Connect(function() IsAxe = false end)
Here is the module script ManagItems;
local module = {} local Popup = require(game.ServerScriptService.PopUp) module.PickUpItem = function(item, amount, player) local Parent = game.Workspace.Items:FindFirstChild(tostring(item), true) if Parent then item:Clone() item.Parent = player.Backpack Popup.PopUpItem(item, amount, player) else print("No item found!") end end return module
So basically when i kill the stone rock, it prints to console saying "No Item Found" Which restricts the script from giving the items. ALSO another thing is the click detector only works when you hold down control and then click, it doesn't work when you click it normally. Please help!
Also need help with giving the item everytime the stone node/rock loses its health, you can probably see i tried with maths but it doesn't work