Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to let a block stay infront of player?

hello beautiful people hope you are having a blessed day i'm making so if the thing is equipped the wall is in front if the player but it is always just next to the player can somebody please help

(ps. I want it to work on a model)

here is the script

	repeat
		local x = script.Parent.Parent.HumanoidRootPart.Orientation.X
		local y = script.Parent.Parent.HumanoidRootPart.Orientation.Y
		local z = script.Parent.Parent.HumanoidRootPart.Orientation.Z

	 clone.PrimaryPart.Position = Vector3.new(game.Players.LocalPlayer.Character.Head.Position)
	clone:SetPrimaryPartCFrame(CFrame.Angles(x,y,z))
	    wait(0.1)
	until script.Parent.Value.Value == true
	if script.Parent.place.Value == false then
		clone:Destroy()	

i have alot alot more script but that is the part i have it to follow the player...

help?

3 comments

1

use RootPart.CFrame.new(CFrame.lookVector * DISTANCE_FROM_OBJECT) + RootPart.Position

1

you'll have to use toEulerAnglesXYZ to maintain the part's rotation, by the way

0

why you put "local stud = 5"?

2 answers

This script should give you the basic idea of what the part needs to do. I prefer welding over setting its position over and over again because it won't ever be perfectly in front of the player.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local model = Instance.new("Model")
		model.Parent = workspace
		
		local inFront = Instance.new("Part")
		inFront.Parent = model
		model.PrimaryPart = inFront
		model:SetPrimaryPartCFrame(character:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0, 0, - 5))
		
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = character:FindFirstChild("HumanoidRootPart")
		weld.Part1 = inFront
		weld.Parent = character:FindFirstChild("HumanoidRootPart")
	end)
end)

3 comments

0

sorry still dont work

0

now im no genius but im quite sure thats not how u weld constraints

0

It's just a weld. I don't think it really matters? (I think. cause im no genius either :/)

local char = game.Players.LocalPlayer.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")

local wall = nil

function weld(a, b)
	local joint = Instance.new("ManualWeld")
	joint.C0 = a.CFrame:Inverse() * b.CFrame
	joint.Parent = a
	joint.Part0 = a
	joint.Part1 = b
	
	return joint
end

game:GetService("UserInputService").InputBegan:Connect(function(input, process)
	if process then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		wall = Instance.new("Part")
		wall.Size = Vector3.new(10, 10, 1)
		wall.Parent = workspace
		wall.CFrame = root.CFrame * CFrame.new(0, wall.Size.Y * .5 - hum.HipHeight * 1.5, -5)
		
		weld(root, wall)
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(input, process)
	if process then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		wall.Parent = nil
	end
end)

only problem would be that the character rotates pretty weirdly due to its center of mass getting trolled

2 comments

0

btw mb1 to activate wall; mb2 to deactivate

0

Nope does not wanna work (BTW I DID DO SOME CHANGES oh sorry caps and i want it to work on a model please)

This discussion is preserved as it was. New answers, comments, and votes are closed.