I want to make a part spawn inside of the player, but i wanted to move the Part back a few studs, there for its not inside the player but has a little distance to the player.
(I have created the part inside the player)
The issue is, it seems like the Part dosen’t want to go a few studs back, and I can’t figure out how.
I have already tried searching on the Developer Forum as the first thing and found nothing, secondly i checked YouTube and found nothing.
Keep in mind its only the position of the part that I need help with.
--
local rep = game:GetService("ReplicatedStorage")
local Cube = rep.Cube
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humPart = char:FindFirstChild("HumanoidRootPart")
local newCube = Cube:Clone()
local humanoid = char:FindFirstChild("Humanoid")
local Weld = newCube.Weld
newCube.Parent = humPart
newCube.Position = humanPart.CFrame.Position + Vector3.new(0,2,0)
newCube.Anchored = false
newCube.Size = Vector3.new(1,1,1)
newCube.CanCollide = true
Weld.Parent = humPart
Weld.Part0 = newCube
Weld.Part1 = humPart
end)
end)
You are adding 2 studs to the Y axis instead of Z. Nevertheless, it is best to use the hmr’s look vector instead of relying on a constant axis. It would also be advisable to use WeldConstraints as they have the relative positions built-in unlike welds, so they’re refined for new work rather than welds
--
local rep = game:GetService("ReplicatedStorage")
local Cube = rep.Cube
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humPart = char:FindFirstChild("HumanoidRootPart")
local newCube = Cube:Clone()
local humanoid = char:FindFirstChild("Humanoid")
local Weld = newCube.WeldConstraint
newCube.Parent = humPart
newCube.CFrame = CFrame.new(humPart.Position + (-hum.CFrame.LookVector * 2), humpart.Position)
newCube.Anchored = false
newCube.Size = Vector3.new(1,1,1)
newCube.CanCollide = true
Weld.Parent = humPart
Weld.Part0 = newCube
Weld.Part1 = humPart
end)
end)