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.
Create a new part named SellPlatform. Customize it to fit the theme of your game.
In SellPlatform, create a new script named SellScript and add a comment.
In SellScript, type local sellPart = script.Parent to get the SellPlatform part.
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.
-- When a player touches the parent object, their items will be sold for gold
local sellPart = script.Parent
-- Gives the player gold for each item they have
local function sellItems(playerItems, playerGold)
-- Gives players 100 pieces of gold for each item
local totalSell = (playerItems.Value * 100)
playerGold.Value = playerGold.Value + totalSell
playerItems.Value = 0
end
local function onTouch(partTouched)
-- Looks for a Humanoid
local character = partTouched.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
-- If a humanoid is found, gets leaderstats and calls sellItems function
if humanoid then
-- Get the player, so changes can be made to the player's leaderstats
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
local playerStats = player:FindFirstChild("leaderstats")
local playerItems = playerStats:FindFirstChild("Items")
local playerGold = playerStats:FindFirstChild("Gold")
-- Sells Items and then changes the player's spaces and money
sellItems(playerItems, playerGold)
end
end
sellPart.Touched:Connect(onTouch)