0% found this document useful (0 votes)
24 views2 pages

Codes

Pet Plant Paradise is a simulator game where players cultivate magical pet plants that evolve and can be traded. The document includes a script for a breakable coin feature, detailing its respawn mechanics and click event handling. The script manages the visibility and position of the coin model upon interaction by players.

Uploaded by

Valeria Cranea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Codes

Pet Plant Paradise is a simulator game where players cultivate magical pet plants that evolve and can be traded. The document includes a script for a breakable coin feature, detailing its respawn mechanics and click event handling. The script manages the visibility and position of the coin model upon interaction by players.

Uploaded by

Valeria Cranea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

3.

"Pet Plant Paradise"


Genre: Simulator
Concept: Players grow magical pet plants that need love and attention. The
plants evolve into different forms (like flowers, trees, or cute creatures). You
can trade plants with others and unlock new seeds.

Code for breaking coins

local clickDetector = script.Parent


local coinModel = clickDetector.Parent

-- Configuration
local respawnTime = 3
local basePosition = coinModel:GetPivot().Position -- Use the model's starting Y position
local respawnAreaMin = Vector3.new(-50, basePosition.Y, -50)
local respawnAreaMax = Vector3.new(50, basePosition.Y, 50)

local isDebounce = false -- Prevent multiple clicks while respawning

-- Helper function to set transparency and collision for all parts in the model
local function setModelState(model, transparency, canCollide)
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Transparency = transparency
descendant.CanCollide = canCollide
end
end
end

-- Function to handle the click event


local function onClick(player)
if isDebounce then return end -- Exit if already processing a click
isDebounce = true

print(player.Name .. " clicked the coin model: " .. coinModel.Name)


-- Add coin awarding logic here if needed

-- Hide the coin model


setModelState(coinModel, 1, false)
-- Wait for respawn time
task.wait(respawnTime)

-- Calculate new random position within the area


local randomX = math.random(respawnAreaMin.X, respawnAreaMax.X)
local randomZ = math.random(respawnAreaMin.Z, respawnAreaMax.Z)
local randomPosition = Vector3.new(randomX, basePosition.Y, randomZ) -- Keep original Y

-- Create the target CFrame (position only, keeps original orientation)


local targetCFrame = CFrame.new(randomPosition)

-- Move the model to the new position


coinModel:PivotTo(targetCFrame)

-- Show the coin model again


setModelState(coinModel, 0, true)

isDebounce = false -- Allow clicking again


end

-- Connect the click event


clickDetector.MouseClick:Connect(onClick)

print("Breakable coin script loaded for:", coinModel.Name)

You might also like