I am making an effect when the player has jumped and landed onto the ground, a part will appear on the floor with a crack decal but the problem is I don’t know how to do the CFrame
local PlayerS = game:GetService('Players')
local DebrisS = game:GetService('Debris')
local EnumMaterial = Enum.Material
local Materials = {
[EnumMaterial.Air] = true,
[EnumMaterial.Water] = true,
}
local CrackPart = script:WaitForChild('Crack')
PlayerS.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(Cha)
local Hum = Cha:WaitForChild('Humanoid')
local HRP = Cha:WaitForChild('HumanoidRootPart')
local IsFalling
local DB
Hum.FreeFalling:Connect(function(Falling)
local LowestFallHeight = 15 -- if studs fallen more than LowestFallHeight then it will create crack
IsFalling = Falling -- make sure that the Humanoid is falling for the first time
if IsFalling and not DB then
DB = true
local MaxHeight = 0
while IsFalling do
local Hight = math.abs(HRP.Position.y)
if Hight > MaxHeight then
MaxHeight = Hight
end
wait()
end
local FallHeight = MaxHeight - HRP.Position.y
-- if the player fell a longer distance than LowestFallHeight and the Material the Humanoid is on top of isn't air and water then create crack
if FallHeight > LowestFallHeight and not Materials[Hum.FloorMaterial] then
local CrackPart_Clone = CrackPart:Clone()
local Weld = Instance.new('Weld')
CrackPart_Clone.Parent = Cha
Weld.Parent = workspace
Weld.Part0 = CrackPart_Clone
Weld.Part1 = workspace.Baseplate
Weld.C0 = HRP.CFrame - HRP.CFrame.p - Vector3.new(0,2.5,0)
DebrisS:AddItem(CrackPart_Clone,1)
end
DB = false
end
end)
Hum.JumpPower = 100
end)
end)
What I have done is i have created a simple raycast that fires down and places the crack on the part that it hits. I have tested this in APS so this should work
local PlayerS = game:GetService('Players')
local DebrisS = game:GetService('Debris')
local EnumMaterial = Enum.Material
local Materials = {
[EnumMaterial.Air] = true,
[EnumMaterial.Water] = true,
}
local CrackPart = script:WaitForChild('Crack')
PlayerS.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(Cha)
local Hum = Cha:WaitForChild('Humanoid')
local HRP = Cha:WaitForChild('HumanoidRootPart')
local IsFalling
local DB
Hum.FreeFalling:Connect(function(Falling)
local LowestFallHeight = 15 -- if studs fallen more than LowestFallHeight then it will create crack
IsFalling = Falling -- make sure that the Humanoid is falling for the first time
if IsFalling and not DB then
DB = true
local MaxHeight = 0
while IsFalling do
local Hight = math.abs(HRP.Position.y)
if Hight > MaxHeight then
MaxHeight = Hight
end
wait()
end
local FallHeight = MaxHeight - HRP.Position.y
-- if the player fell a longer distance than LowestFallHeight and the Material the Humanoid is on top of isn't air and water then create crack
if FallHeight > LowestFallHeight and not Materials[Hum.FloorMaterial] then
local CrackPart_Clone = CrackPart:Clone()
local Weld = Instance.new('Weld')
CrackPart_Clone.Parent = Cha
Weld.Parent = workspace
Weld.Part0 = CrackPart_Clone
Weld.Part1 = workspace.Baseplate
--Raycasting
local ray = Ray.new(HRP.CFrame.p,Vector3.new(0,-20,0))
local part,position,surfaceNormal = workspace:FindPartOnRay(ray,Cha)
local cross = Vector3.new(0,1,0):Cross(surfaceNormal)
local angle = math.asin(cross.magnitude)
CrackPart_Clone.CFrame = CFrame.new(position + surfaceNormal - Vector3.new(0,1,0))
*CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle)
--
DebrisS:AddItem(CrackPart_Clone,1)
end
DB = false
end
end)
Hum.JumpPower = 100
end)
end)
That doesn’t account for slopes or otherwise uneven surfaces. To make a crack appear correctly on most surfaces you need to use the surface normal, as explained here;