Spawn a part in the mouse position

How i can spawn a part in the mouse location
This is my script :

local Replicated = game:GetService("ReplicatedStorage")
local Storage = game:GetService("ServerStorage")
local Remote = Replicated:FindFirstChild("CreateWall")

Remote.OnServerEvent:Connect(function(Player)
	local Wall = Storage:FindFirstChild("Wall"):Clone()
	Wall.CFrame = Player.Character.HumanoidRootPart.CFrame *CFrame.new(Vector3.new(0,0,-5))
	Wall.Parent = workspace
	task.wait(3)
	Wall.Anchored = false
	Wall.CanCollide = false
end)

4 Likes

when u fire that RemotEvent from the client, send LocalPlayer:GetMouse().Hit.CFrame to the Server, and use that cframe for the wall. I think that will work im not sure though:

local Replicated = game:GetService("ReplicatedStorage")
local Storage = game:GetService("ServerStorage")
local Remote = Replicated:FindFirstChild("CreateWall")

Remote.OnServerEvent:Connect(function(Player,MouseCFrame)
	local Wall = Storage:FindFirstChild("Wall"):Clone()
	Wall.CFrame = MouseCFrame -- put offsets if u want to
	Wall.Parent = workspace
	task.wait(3)
	Wall.Anchored = false
	Wall.CanCollide = false
end)
1 Like

Instead of hit.cframe he must do hit.p

I know i put it because he was using cframe so…

1 Like

try this

--local script--
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	game.ReplicatedStorage.Spawner:FireServer(mouse.Hit)
end)

--Server script--
local Replicated = game:GetService("ReplicatedStorage")
local Storage = game:GetService("ServerStorage")
local Remote = Replicated:FindFirstChild("CreateWall")

Remote.OnServerEvent:Connect(function(Player, Pos)
	local Wall = Storage:FindFirstChild("Wall"):Clone()
	Wall.CFrame = Pos
	Wall.Parent = workspace
	task.wait(3)
	Wall.Anchored = false
	Wall.CanCollide = false
end)
1 Like

Oh yeah the mouse.Hit might already be a CFrame heh

And i got this too


That is the script :
image
This is in a tool

Are you sending the player instance from the local script to the remoteevent?
if so, remove it since remotevents sends the player automatically from client to server.
It should be just

RemoteEvent:FireServer(Mouse.Hit)

from the client, and

RemoteEvent.OnServerEvent:Connect(function(Plr,Position)

from the server

1 Like