I cant figure out how i can make a placeable landmine/model tool

I have bee trying for 1/2 weeks of trying to figure out how i would make a tool spawn a model infront of the player

I want to make a tool that spawns a model(force field generator/Landmines)

infrontof the player upon clicking the tool
i have tried multiple ways to approach this but all failed to reach the desired result

How would i make it spawn a model or part upon using clicking and using a tool spawning infront of the player like placing a landmine
and im completely lost

1 Like

So, you’d need a client script for detecting click, and showing a placeholder part that will show the player where’s the current placement along with a green/red color based on wherether the model is placeable or not, for the placeholder you could just clone the handle move it around and make it uncollidable, on click if the placeholder is placeable(green) fire a remote event giving it the tool, a server sided script that on remote event fire from client checks a few things, it should check if the player is alive, has a character etc, secondly of all it should check if the model is actually placeable, then it should check if the player has the tool equipped, once all these checks are done, you can clone the handle, and use the same code used on client for the placeholder moving to place the handle, then delete the tool.

1 Like

More details on the placeholder and server placement script:
-It’s suggested to use a partsinpart check to make sure there’s nothing obstructing;
-Raycasting comes handy when placing in non-flat floors or plateaus, I heavily suggest it.

i understand the use of client>remotevent>server to clone but i cant figure out how to make it spawn infront of the player since currently it only spawns in it original place or to check if a part is obstructing it before spawning

You can use PivotTo if it’s a model or CFrame set if it’s a part.
You can find the usage of partsinpart here: GetPartsInPart
Edit: For checking before spawning you can use: GetPartBoundsInBox instead, giving it the cframe and the size of the building

I tried this out in studio, and it seemed to work for me.
please read the comments, it contains important instructions.

local Model = -- Define Your Model
local PrimaryPart = Model.PrimaryPart

-- Make Sure that the Model has A Primary Part Set
-- Anchor the PrimaryPart, Unanchor All the Other Parts
-- SetCanCollide of All Parts to true
-- Weld the Other Parts to the Primary Part Using Weld Constraints

local Character = script.Parent -- Define Your Character

local Params=RaycastParams.new()
Params.FilterType=Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances={Character,Model}
Params.IgnoreWater=true

local Origin=Character.HumanoidRootPart.CFrame*CFrame.new(Vector3.new(0,0,-3))
Origin=Origin.Position
local Raycast=workspace:Raycast(Origin,Vector3.new(0,-100,0),Params)
if Raycast then
	local Position=Raycast.Position
	local InstanceHit=Raycast.Instance
	local P=Vector3.new(Position.X,InstanceHit.Position.Y+(InstanceHit.Size.Y/2)+(PrimaryPart.Size.Y/2),Position.Z)
	PrimaryPart.CFrame=CFrame.new(P,Character.HumanoidRootPart.CFrame.LookVector+P)
	Model.Parent=workspace	
end
-- The Model should have spawned infront of the character now.
1 Like

if i were to define the player i`d use a local script with the tool correct?
and aswell id use a onserver function to trigger the spawning?
Thank you in advance!

if you want everyone to see the landmine,
use a remote event and do the raycasting and actual spawning on the server.

yes, Player can only be defined using LocalScripts.

game.Players.LocalPlayer

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.