I’m trying to make it so that this red part will send down a raycast -1000 studs on the Y axis, this is so that if the raycast hits a part then the red part will update its CFrame relative to the player’s character while also making it so that the red part automatically goes to the ground instead of floating in the air.
Expected:
Reality:
Although, when I tried this it didn’t seem to work…
Here’s the code:
local pianoMark = Instance.new("Part")
pianoMark.BrickColor = BrickColor.new("Persimmon")
pianoMark.Transparency = .5
pianoMark.Parent = Tool
pianoMark.Anchored = true
pianoMark.Size = Vector3.new(Piano.Size.X, 1, Piano.Size.Z)
local basePianoMarkDistance = -7
local pianoMarkMultiplier = 0
local raycastResult
function pianoMarkPosition()
pianoMark.CFrame = Player.Character.PrimaryPart.CFrame * CFrame.new(0, -4, basePianoMarkDistance + -pianoMarkMultiplier)
raycastResult = workspace:Raycast(pianoMark.Position, Vector3.new(0, -1000, 0))
if raycastResult then
if raycastResult.Instance:IsA("Part") then
pianoMark.CFrame = (Player.Character.PrimaryPart.CFrame * CFrame.new(0, -4, basePianoMarkDistance + -pianoMarkMultiplier)) + CFrame.new(raycastResult.Position)
end
end
end
game:GetService("RunService").Heartbeat:Connect(function()
if UserInputService:IsKeyDown(Enum.KeyCode.Y) and pianoMarkMultiplier ~= 100 then
print("a")
pianoMarkMultiplier += 1
elseif UserInputService:IsKeyDown(Enum.KeyCode.H) and pianoMarkMultiplier ~= 0 then
print("b")
pianoMarkMultiplier -= 1
end
end)