✓ Accepted answer
You should thank me a lot since I basically wrote the script for you:
uis = game:GetService("UserInputService")
player = game.Players.LocalPlayer
part = nil
buildingHeight = 20
building = game.Workspace.building
uis.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
part.CFrame = player.Character.Torso.CFrame * CFrame.new(0,3,0)
part.Orientation = Vector3.new(0,0,0)
if part.Position.Y > buildingHeight then
local difference = buildingHeight - part.Position.Y
part.CFrame = part.CFrame * CFrame.new(0,difference,0)
end
part.Position = Vector3.new(building.Position.X,part.Position.Y,building.Position.Z)
end
end)
This will get part in the building's center (add offset to the Vector3 in line 20 if you don't want the part to be in the building brick) 3 studs above player's torso's position or at the top of building if player is above it. It MUST be placed in a LocalScript to work, which has to be placed in the player's character's model (or StarterPack / StarterGui).
1 comment
Thank you