#how to make cylinder spawn when mouse clicks ground
1 messages · Page 1 of 1 (latest)
position here is higher when i press
here it's lower
local script in StarterPlayerScripts: `local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local plantEvent = ReplicatedStorage:WaitForChild("PlantRequest")
mouse.Button1Down:Connect(function()
local target = mouse.Target
if target and target.Name == "SoilBase" then
local pos = mouse.Hit.Position
local soilY = target.Position.Y + (target.Size.Y / 2) -- top surface of soil
plantEvent:FireServer(pos, soilY)
end
end)
`
script in Server Script: `local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plantEvent = ReplicatedStorage:WaitForChild("PlantRequest")
local patchTemplate = ReplicatedStorage:WaitForChild("PlantPatch")
-- Minimum distance between patches
local MIN_DISTANCE = 4
local function isTooClose(position)
for _, patch in pairs(workspace:GetChildren()) do
if patch.Name == "PlantPatch" then
local dist = (patch.Position - position).Magnitude
if dist < MIN_DISTANCE then
return true
end
end
end
return false
end
plantEvent.OnServerEvent:Connect(function(player, position, soilY)
if isTooClose(position) then
print("Too close! Pick another spot.")
return
end
local newPatch = patchTemplate:Clone()
-- Perfect placement: sits exactly on top of soil
newPatch.Position = Vector3.new(
position.X,
soilY + (newPatch.Size.Y / 2),
position.Z
)
-- Correct flat orientation for the cylinder
newPatch.Orientation = Vector3.new(0, 90, 90)
newPatch.Parent = workspace
end)
`
get it?
i've to sleep now
if u have solution please write
--Script (StarterPlayerScripts)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local plantEvent = ReplicatedStorage:WaitForChild("PlantRequest")
mouse.Button1Down:Connect(function()
local target = mouse.Target
if target and target.Name == "SoilBase" then
local pos = mouse.Hit.Position
local soilY = target.Position.Y + (target.Size.Y / 2) -- top surface of soil
plantEvent:FireServer(pos, soilY)
end
end)
--Script (ServerScriptService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plantEvent = ReplicatedStorage:WaitForChild("PlantRequest")
local patchTemplate = ReplicatedStorage:WaitForChild("PlantPatch")
-- Minimum distance between patches
local MIN_DISTANCE = 4
local function isTooClose(position)
for _, patch in pairs(workspace:GetChildren()) do
if patch.Name == "PlantPatch" then
local dist = (patch.Position - position).Magnitude
if dist < MIN_DISTANCE then
return true
end
end
end
return false
end
plantEvent.OnServerEvent:Connect(function(player, position, soilY)
if isTooClose(position) then
print("Too close! Pick another spot.")
return
end
local newPatch = patchTemplate:Clone()
-- Perfect placement: sits exactly on top of soil
newPatch.Position = Vector3.new(
position.X, soilY + (newPatch.Size.Y / 2), position.Z)
-- Correct flat orientation for the cylinder
newPatch.Orientation = Vector3.new(0, 90, 90)
newPatch.Parent = workspace
end)
had a hard time reading that sorry
is anything printing when you try to plant? or no
lol grow a garden clone and that looks like ai. if you struggling with this you gonna have a hell of a time when you get to saving/loading these things and doing the offline growing thing. ai doesn't understand what you mean by "perfect placement" and "sit exactly on top of the soil" no matter how many times you try to ask it
https://create.roblox.com/docs/tutorials/fundamentals/coding-1/coding-fundamentals
oh yeah it does how did i not realize that
@fallen light When ur done with grow a garden modded send that server link fr
Im not making that. Im making my own game, Build a Farm
Ohhh
Than still send the link once done
are we fr
either way that's just overfarmed
😭
well if you want to make a clone of a game im not stopping you
but original ideas are better
there's a lot more stuff you can do
im not scripter my friend is thats why i don't know how to make that, so i asked AI I admit (bc my friend was sleeping at that moment)
im more like maps, gui,ui, animations etc
i was referring to font stuff
*text* makes italics **text** makes bold ||text|| adds spoiler [text](link) changes link text __text__ makes underline ~~text~~ strikes through