I am making an object pick-up system for my game. Right now, everything is working, except for keeping the mesh in front of the players face. This is similar to the game "Murder"s pick-up system. I also want this to be serverside. Here is my code:
Client-Side Code:
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
game.ReplicatedStorage.events.PickUp:FireServer()
print("player picked up")
end
end)
game:GetService("UserInputService").InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
game.ReplicatedStorage.events.PlaceDown:FireServer()
print("player put down")
end
end)
Server-Side Code:
local stop = 0
local x
local y
local z
game.ReplicatedStorage.events.PickUp.OnServerEvent:Connect(function(player)
local character = player.Character
local magnitude = (character.Head.Position - script.Parent.Position).Magnitude
if magnitude <= 5 then
while stop == 0 do
x = character.Head.Position.X + 5 -- this is where i need help. i can make it stay with the player, but not in front of their face.
y = character.Head.Position.Y
z = character.Head.Position.Z + 5
script.Parent.Position = Vector3.new(x,y,z)
wait(0.05)
end
end
end)
game.ReplicatedStorage.events.PlaceDown.OnServerEvent:Connect(function()
stop = 1
wait(0.5)
stop = 0
end)
As you may be able to tell, my code right now just moves it to the players X and Z + 5. Hopefully, there is a fix for this. Thanks!

5 comments
This is so close! Except that it appears to put the mesh at the side of my head. I also tested with a normal part, and still the same result. Thanks!
You want it directly in front of the player's head? Just change the CFrame.new(5,0,5) to CFrame.new(0,0,5) and I think that'll fix it
If that doesn't work try CFrame.new(5,0,0) ... I forget which is which lol
Yeah, it still stays at the side with both.
OK I got it. It is CFrame.new(0,0,-5)