I want to make it so that if they click a GUI, they can duplicate a tree and move it around to the place they want it to go. idk how to start making this. I do know some basic programming. But ill need some help.
Change the title into topic you want to talk. Also, remember not everyone have many time to stay, explain, teach you about this so please be more specific on what you want. Provide some pictures if needed.
Do you want to make a building game like bloxburg
? When you click on something, you can drag the furnitures or the “Tree”?
A Post Inside of Scripting Support should not be about asking to make a script, your supposed to already have one and then paste it in their, then state your problems, check the rules for scripting support please.
Also, try Searching up a YouTube tutorial.
He didn’t asks for scripts, he’s just asking how to
Clone a tree you have made and use mouse service to make it follow the mouse and get placed when you click.
" Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category. "
About the Scripting Support category - Help and Feedback / Scripting Support - DevForum | Roblox
You could use a modified version of this placement system to place a tree once a GUI button is clicked.
No I mean where do I start? Like what do I do first.
You will have to use RemoteEvents. You can learn more about them here: RemoteEvent | Roblox Creator Documentation
- Make a LocalScript inside the button
- Make a RemoteEvent named “Placement” inside the button
- Make a Script inside the button
In our LocalScript do:
local button = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
button.MouseButton1Click:Connect(function()
mouse.Button1Down:Connect(function()
script.Parent.Placement:FireServer(mouse.Hit.p)
end)
end)
Then, in the server script do:
script.Parent.Placement.OnServerEvent:Connect(function(plr, mousePosition)
local tree = workspace.Tree:Clone()
tree.Parent = workspace
tree.Position = mousePosition
print(plr.Name .. " placed a tree!")
end)
Pretty basic, not tested. You may have to adjust it according to your needs.
Note: this is exploitable as it uses a RemoteEvent. Consider doing server side checks to prevent exploiters.
That’s for you more to decide, I recommend learning scripting with the online first edition lua book
You’ll need to use a RemoteEvent, LocalScript, a serverscript which will handle the remote and primary part inside your tree.
This example may not work since I wrote this all on mobile.
button.Activated:Connect(function() -- connect a new event
local preview = tree:Clone() -- create a preview of where the player is putting the tree
local _, size = preview:GetBoundingBox() -- this is to make the tree stand on the ground
local offset = Vector3.new(0, size.Y / 2, 0) -- how much higher the tree will be
mouse.TargetFilter = tree.PrimaryPart -- so the tree doesnt keep going to our camera
preview:SetPrimaryPartCFrame(mouse.Hit + offset) -- set the tree's cframe
preview.Parent = workspace -- make the preview visible
for _, object in pairs(preview:GetDescendants()) do -- loop through the tree's objects
if object:IsA('BasePart') or object:IsA('UnionOperation') then -- check if its a part
object.CanCollide = false -- make it not collidable
object.Transparency = .7 -- make it transparent
object.Material = Enum.Material.Neon -- change the material (optional)
object.Color = Color3.new(1, 1, 1) -- change the color
end
end
local connection = mouse.Move:Connect(function() -- connect a event
preview:SetPrimaryPartCFrame(mouse.Hit + offset) -- set the tree's cframe
end)
mouse.Button1Down:Wait() -- wait until the player has clicked
connection:Disconnect() -- stop moving the preview
preview:Destroy() -- remove the preview
remote:FireServer(mouse.Hit + offset) -- make the tree visible to everybody
end)
remote.OnServerEvent:Connect(function(player, cframe) -- connect a event to place the tree
local newTree = tree:Clone() -- duplicate one
newTree.Name = player.Name .. '\'s Tree' -- name it (optional)
newTree:SetPrimaryPartCFrame(cframe) -- set the cframe
newTree.Parent = workspace -- parent it
end)