To make a part add +1 emerald when touched, you can use a script in the part’s parent to detect the touch event and then update the player’s “Emeralds” value in their leaderstats. Here’s how you can do it:
Insert a script into the part’s parent (for example, Workspace) or directly into the part itself. Here’s an example of the script that could be placed in the part’s parent:
local part = script.Parent -- Assuming the script is a child of the part
local function onTouched(hit)
local character = hit.Parent -- The part that touched the object
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local emeralds = leaderstats:FindFirstChild("Emeralds")
if emeralds then
emeralds.Value = emeralds.Value + 1
-- You can add more logic here, such as sound effects or removal of the part.
end
end
part.Touched:Connect(onTouched)