I’m trying to create a script that will create cracks below a player when he lands. **The problem is sometimes when the player landed the cracks end up in the air instead of on the ground.
Here is a video:
Here is my code:
elseif newState == Enum.HumanoidStateType.Landed then
local camera = cameraModule.Init(workspace.CurrentCamera)
local shakePresets = cameraModule.ShakePresets
local shake = camera:CreateShake()
shake:ShakeSustain(shakePresets.Explosion) wait(0.5)
shake:StopSustained(0.5)
local leftLegCFrame = char["Left Leg"].CFrame
local leftLegSize = char["Left Leg"].Size
game.ReplicatedStorage.CreateCracks:FireServer(leftLegCFrame:ToWorldSpace(CFrame.new(1,-leftLegSize.Y/2,0)))
end
This is just an excerpt of the client script, everything makes it to the server.
Here is the server callback:
local cracksImage = “rbxassetid://5832182890”
game.ReplicatedStorage.CreateCracks.OnServerEvent:Connect(function(player,crackedPartPos)
local char = player.Character or player.CharacterAdded:Wait()
local crackedPart = Instance.new("Part", workspace)
crackedPart.Size = Vector3.new(20,.001,20)
crackedPart.CanCollide = false
crackedPart.Transparency = 1
crackedPart.Anchored = true
crackedPart.CFrame = crackedPartPos
local cracks = Instance.new("Decal",crackedPart)
cracks.Texture = cracksImage
cracks.Face = "Top"
wait(5)
crackedPart:Destroy()
end)
What code can I add to prevent this from happening?
I believe it’d be easier to cast a ray directly to the ground once they land. This way, if any server lag, glitches, etc arise then this system wont break. Once you have the rays position of the land you can simply create the decal at that given spot.
Interesting. You adjusted by “minus legsize” but it appears to have gone up, not down. I’m terrible at this cframe stuff, but I’d flip that sign just to see if that fixed it. If that goes the wrong direction, then tLegCframe starts at the HRP. You might need to get rid of the “/2” instead, or perhaps Humanoid.HipHeight.