Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[QUESTION] Best way to make a brick always in front of player?

Asked by
Oficcer_F 207 Moderation Voter
5 years ago

So, basically I am making a brick that when a tool is equipped the brick will be infront of the player. Also if he changes position, I tried to use

player.Character.Head.Position.Changed:Connect(function()

end)

But as I have found out you cannot use a changed event on a position (or can you?). What other way can I use to always have the brick infront of player.

BTW, I know like how to have position and placing the brick, but how can I have the brick always infront and not the first position value?

1
No. You cannot. Position does not fire changed. In fact the properties that relate to physics don't change, like in your example Position. User#19524 175 — 5y
0
But how can I do it then? Oficcer_F 207 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

You can find out more here, but after bit of testing, I find that this probably works the best:

local thing = Instance.new("Part")
thing.Size = Vector3.new(1,1,1)
thing.Anchored = true
thing.BrickColor = BrickColor.Red()
thing.Parent = workspace
game:GetService("RunService").RenderStepped:Connect(function()
    thing.CFrame = CFrame.new(script.Parent:GetPrimaryPartCFrame() * Vector3.new(0,0,-5))
end)

This local script is in the player character, I do not recommend doing some of the things I'm doing in this script as this was hastily thrown together to show how to do this. But the only line that you should use is line 7 as that places it 5 studs in front of the humanoid root part.

So, a basic explanation on what this does:

It first creates a 1x1x1 red part and every frame, it puts the thing in front of the player.

So, as incapaz said, "position does not fire changed", so other things can be used. For example: the HeartBeat, Renderstepped, and Stepped functions of runservice, and the while loop.

Also, I would recommend using a local script to avoid the latency that comes with remote functions and remote events

Ex:

local thing = --whatever part you want to place in front of the player
local head =  game.Players.LocalPlayers.Charcter:FindFirstChild("Head")
local rs = game:GetService("RunService")
rs.RenderStepped:Connect(function()
    if head then
        thing.CFrame = CFrame.new(head.CFrame * Vector3.new(0,0,-5))
    end
end)
Ad
Log in to vote
0
Answered by 5 years ago

Use Cframe Read Wiki http://wiki.roblox.com/index.php?title=CFrame

Answer this question