I’m trying to have a survival game where you gather wood and use it to build wooden planks to shelter up etc. I have already got the GUI and the wood counter sorted so that’s done.
However, I’m unsure on how to clone a part from ServerStorage and position it to the raycast of my cursor. Preferably this would be without the use of tools, so it would have to be client based or something like that.
I want the parts to show up for everyone, though, so fully client based wouldn’t be a good solution. I’m also unsure on what script to use and what to parent it to.
If someone could help me out I would appreciate it. Thanks!
You need both a LocalScript and a server Script. The LocalScript handles everything related to taking input from the builder and e.g. showing “ghost” models where they’re aiming or whatever over effects you want the builder to see.
When the builder actually wants to build something, send an event to the server Script which then actually does the building, assuming the client sent over valid parameters. That way the building gets replicated to all clients, and the server has full authority over what can or cannot be built in what situations.
The server Script goes in ServerScriptService. Since you’re not using Tools, you can put the LocalScript in StarterPlayer.StarterScripts. That way it runs when the player joins. Use mouse = player:GetMouse() and mouse.UnitRay.Origin, mouse.UnitRay.Direction to get ray parameters.
The logic for correctly placing models can be pretty complex, so if I were you I’d get everything working with basic placement logic (just SetPrimaryPartCFrame wherever the mouse ray hits something), and then make a separate post to get help on that or update this post.
Is there something specific you’d like a more detail explanation on? Sometimes it’s best to just start somewhere and see how far you get. If you get stuck, feel free to post a follow up question here or in a new post.