How would I make a block that follows Infront of a player, instead of simply placing Infront of it?
What I have so far:
local wrksp = game:GetService("Workspace")
local builditems = repst.BuildItems
local b1 = builditems.trainblock
local player = game.Players.LocalPlayer
local clickframe = script.Parent
local Character = player.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local cplace = script.Parent.ConfirmPlace
local Time = tick()
clickframe.MouseButton1Click:Connect(function()
local b1 = builditems.trainblock:Clone()
b1.Transparency = 0.5
b1.Material = "ForceField"
b1.BrickColor = BrickColor.new(3,165,0)
b1.Parent = wrksp
b1.CFrame = CFrame.new(HumanoidRootPart.Position.X, HumanoidRootPart.Position.Y-2.25, HumanoidRootPart.Position.Z-2.25)
cplace.Visible = true
if tick() - Time < 0.5 then -- tick() - Time would be the time elapsed
print("double Click!")
cplace.Visible = false
end
Time = tick()
end)```
local wrksp = game:GetService("Workspace")
local builditems = repst.BuildItems
local b1 = builditems.trainblock
local player = game.Players.LocalPlayer
local clickframe = script.Parent
local Character = player.Character
local humanoid: Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local cplace = script.Parent.ConfirmPlace
local Time = tick()
local connection: RBXScriptConnection
local function StartFollowing(part: BasePart)
if connection and connection.Connected then
connection:Disconnect()
end
connection = humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
part.CFrame = HumanoidRootPart.CFrame - Vector3.new(0, 2.25, 2.25)
end)
end
local function StopFollowing(part: BasePart)
if connection and connection.Connected then
connection:Disconnect()
end
part:Destroy()
end
clickframe.MouseButton1Click:Connect(function()
local b1 = builditems.trainblock:Clone()
b1.Transparency = 0.5
b1.Material = "ForceField"
b1.BrickColor = BrickColor.new(3,165,0)
b1.Parent = wrksp
StartFollowing(b1)
cplace.Visible = true
if tick() - Time < 0.5 then -- tick() - Time would be the time elapsed
print("double Click!")
cplace.Visible = false
end
Time = tick()
end)