Players will need something like an ax or a shovel to gather items with. In Roblox, items that players can equip and use are called tools. This lesson uses a starter tool with all the parts and an animation already made that can be customized later.
To give players a tool at the start of the game, place it into the StarterPack.
Download the starter tool here if it’s not already on your computer. Remember where you save it to.
In Explorer, under Workspace, right-click on StarterPack.
4. Find the downloaded starter tool on your computer and open it.
5. Rename StarterTool to the name you want players to see. For example, Scoop.
6. Playtest your game. Players should be equipped with the scoop as soon as they start the game.
-- Used to give players items when tool hits cupcakes
local tool = script.Parent
local scoop = tool.Scoop
local backpack = tool.Parent
local player = backpack.Parent
local playerStats = player:FindFirstChild("leaderstats")
local playerItems = playerStats:FindFirstChild("Items")
local playerSpaces = playerStats:FindFirstChild("Spaces")
local function onTouch(partTouched)
local canHarvest = partTouched.Parent:FindFirstChild("CanHarvest")
if canHarvest then
if canHarvest.Value == true and playerItems.Value < playerSpaces.Value then
playerItems.Value = playerItems.Value + 1
canHarvest.Value = false
-- Reset partTouched, the harvested item
partTouched.Transparency = 1
partTouched.CanCollide = false
wait(5)
-- Make the harvested item reappear and usable again
canHarvest.Value = true
partTouched.Transparency = 0
partTouched.CanCollide = true
end
end
end
scoop.Touched:Connect(onTouch)