Making a part's position almost equal to a character's position

So I made a button that spawns parts when you click it, but it seems to spawn them in the default spot. Can somebody help?

The local script
local button = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")




button.MouseButton1Down:Connect(function()
	local Players = game:GetService("Players")
	local player = Players.LocalPlayer
	local characterPosition = player.Character.HumanoidRootPart.Position
	
	print(characterPosition)
	remoteEvent:FireServer(characterPosition)
end)
The Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")

local function spawnPart (characterPosition)
	local part = Instance.new("Part")
	part.Name = "Part"
	part.Parent = game.Workspace
	part.Position = Vector3.new()
	part.Size = Vector3.new(5,5,5)
	part.Material=Enum.Material.Cobblestone
end

remoteEvent.OnServerEvent:Connect(spawnPart)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")

local function spawnPart (player, characterPosition)
	local part = Instance.new("Part")
	part.Name = "Part"
	part.Parent = game.Workspace
	part.Position = characterPosition
	part.Size = Vector3.new(5,5,5)
	part.Material=Enum.Material.Cobblestone
end

remoteEvent.OnServerEvent:Connect(spawnPart)

The modifications I made should work. OnServerEvent makes the first parameter of the function it uses the player that called the event. So to use the characterPosition the client passes, you have to add player as the first parameter, then characterPosition. I saw you didn’t use characterPosition and I assume it’s because you ran into an error when you did.

1 Like

@hamsterloverboy3 Still not working right. It’s just getting stuck on that one position line.

Local Script
local button = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")




button.MouseButton1Down:Connect(function()
	local Players = game:GetService("Players")
	local player = Players.LocalPlayer
	local characterPosition = player.Character.HumanoidRootPart.Position
	
	print(characterPosition)
	remoteEvent:FireServer(player,characterPosition)
end)
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")

local function spawnPart (player, characterPosition)
	local part = Instance.new("Part")
	part.Name = "Part"
	part.Parent = game.Workspace
	part.Position = characterPosition
	part.Size = Vector3.new(5,5,5)
	part.Material=Enum.Material.Cobblestone
end

remoteEvent.OnServerEvent:Connect(spawnPart)

It turns out that Position for parts is not replicated. I think this might be the issue. Although I did see you changed a line in the local script.

You don’t need to pass player to FireServer from the local script:

	remoteEvent:FireServer(player,characterPosition)

Change it back to this:

	remoteEvent:FireServer(characterPosition)

If it is a replicated issue than you should just use the player parameter from the server script and fetch the position that way.

Try changing your characterPosition variable in your server script to player.Character.HumanoidRootPart.Position.

Ie:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")

local function spawnPart (player, characterPosition)
	local part = Instance.new("Part")
	part.Name = "Part"
	part.Parent = game.Workspace
	part.Position = player.Character.HumanoidRootPart.Position
	part.Size = Vector3.new(5,5,5)
	part.Material=Enum.Material.Cobblestone
end

remoteEvent.OnServerEvent:Connect(spawnPart)

Perfect! Thanks for the help!
robloxapp-20201106-1456102.wmv (1021.0 KB)

You probably should just let the server handle the Position to place the block.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")

local function spawnPart (player)
	local part = Instance.new("Part")
	part.Name = "Part"
	part.Parent = game.Workspace
	part.Position = player.Character.HumanoidRootPart.Position
	part.Size = Vector3.new(5,5,5)
	part.Material = Enum.Material.Cobblestone
end

remoteEvent.OnServerEvent:Connect(spawnPart)

Then for the local script you should just be able to do:

local button = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SpawnPartRemoteEvent")

button.MouseButton1Down:Connect(function()
	remoteEvent:FireServer()
end)