You're not even using the mousePos parameter that you put into the function. That's the problem.
I'm going to assume that mousePos's argument is the position of the player's Mouse at the time that they had clicked Button1 (left mouse button). Here's a really simple example of spawning a part where the player clicks:
Local
local event = game:GetService("ReplicatedStorage"):WaitForChild("MouseEvent")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
event:FireServer(mouse.Hit.Position)
end)
Server
local event = game:GetService("ReplicatedStorage"):WaitForChild("MouseEvent")
event.OnServerEvent:Connect(function(client, mousePos)
if client then
local f = game:GetService("ReplicatedStorage"):WaitForChild("BlockStore")
local block = f.Block:Clone()
block.Position = mousePos
block.Parent = workspace
end
end)
Now for the explanation.
Button1Down is an event of the player's Mouse object that fires whenever the player clicks their left mouse button. mouse.Hit is the CFrame of the mouse that represents the 3D space that the mouse clicked on. When the RemoteEvent named MouseEvent fires the OnServerEvent script signal, it has to pass two arguments to its given parameters:
- The client (player) that fired the event (represented by
client)
- A tuple of arguments that was included within the parenthesis of
FireServer(). If no 2nd, 3rd, etc. parameter is defined for the function to use, this argument is not assigned. The same happens if nothing is put in FireServer()'s parenthesis when the function is called.
When the signal fires, the script checks to see if client exists (meaning that the player associated with said client is still in-game). If it passes the fail safe, the script will clone the child of BlockStore, being Block, and do two things:
- Assign the
Position of the part to mouse.Hit.Position, aka mousePos.
- Parent the clone to Workspace.
I personally think that you may have overcomplicated this process.
3 comments
please give a script
i was edit
Is this what you're looking for? https://devforum.roblox.com/t/how-to-make-a-part-spawn-in-front-of-a-player/101426