The Footsteps Stay When I Die

In my game I have a footstep system with a server script script and a client script for the footstep system the client looks like this


--#Services
local tweenService = game:GetService("TweenService")
local debris = game:GetService("Debris")
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
--#Objects
local folder = workspace.FootprintFolder
local mainFolder = replicatedStorage.Footsteps
local remoteEvent = mainFolder.FootstepsEvent
local configuration = mainFolder.FootstepsConfig

--#Constants
local fadeTime = configuration.FadeTime.Value
local frequency = configuration.Frequency.Value
local viewOtherPrints = configuration.ViewOtherPrints
local useFloorColor = configuration.UseFloorColor
local useFootSize = configuration.UseFootSize
local particlesOnMaterial = configuration.ParticlesOnMaterial
local notMoving = Vector3.new(0, 0, 0)
local defaultParticleFade = 0.1

--#Functions
local RayCast = function(origin,target,ignorelist)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = (ignorelist) 
	local raycast = workspace:Raycast(origin,target,params)

	if raycast then
		return raycast
	else
		return nil
	end
end
local createFootPrint = function(leg, hitnormal, hitPosition,hit,hitmaterial)
	local footprint = script.Footprint:Clone()
	footprint.Parent = folder
	footprint.CFrame = CFrame.new(hitPosition, footprint.Position+hitnormal)
	footprint.Orientation = leg.Parent.HumanoidRootPart.Orientation
	
	if useFootSize.Value == true then
		footprint.Size = Vector3.new(leg.Size.X, 0.1, leg.Size.Z)
	end
	if useFloorColor.Value == true then
		if tostring(hit.Name) == "Terrain" then
			footprint.Color = workspace.Terrain:GetMaterialColor(hitmaterial)
		else
			footprint.BrickColor = hit.BrickColor
		end
	end
	if particlesOnMaterial.Value == true then
		local player = game.Players.LocalPlayer
		local findParticle = particlesOnMaterial:FindFirstChild(hitmaterial)
		if findParticle then
			local particle = findParticle:Clone()
			particle.Parent = footprint
			local waittime = particle:FindFirstChild("HowLongToLast").Value or 0.5
			coroutine.wrap(function()
				particle.Enabled = true
				task.wait(waittime)
				particle.Enabled = false
				task.wait(particle.Lifetime.Max)
				particle:Destroy()
			end)()
		end
	end
	return footprint
end
local tween = function(t, instance, properties, style, direction, waitUntilDone)
	local info = TweenInfo.new(t, Enum.EasingStyle[style], Enum.EasingDirection[direction])
	local tween = tweenService:Create(instance,info,properties)
	tween:Play()
	if waitUntilDone == true then
		tween.Completed:Wait()
	end
end

--#Event
replicatedStorage.Footsteps.FootstepsEvent.OnClientEvent:Connect(function(char)
	repeat task.wait() until char
	local startFootprints = true
	local humanoid = char:FindFirstChild("Humanoid") or char:WaitForChild("Humanoid", 5)
	
	while startFootprints == true do
		task.wait()
		if humanoid.MoveDirection ~= notMoving then
			local leftLeg = char:FindFirstChild("Left Leg") or char.LeftFoot
			local rightLeg = char:FindFirstChild("Right Leg") or char.RightFoot

			local raycastr = RayCast(rightLeg.Position, leftLeg.CFrame.UpVector * -3, {char, folder})
			
			if raycastr then
				local hit, hitnormal, hitposition, hitmaterial = raycastr.Instance, raycastr.Normal, raycastr.Position, raycastr.Material
				if hit.Parent ~= folder then
					local rightprint = createFootPrint(rightLeg,hitnormal,hitposition,hit,hitmaterial)
					tween(fadeTime, rightprint, {Transparency = 1}, "Linear", "Out", false)
					debris:AddItem(rightprint,fadeTime*2)
				end
			end
			task.wait(frequency)
			local raycastl = RayCast(leftLeg.Position, leftLeg.CFrame.UpVector * -3, {char, folder})
			if raycastl then
				local hit, hitnormal, hitposition, hitmaterial = raycastl.Instance, raycastl.Normal, raycastl.Position, raycastl.Material
				if hit.Parent ~= folder then
					local leftprint = createFootPrint(leftLeg,hitnormal,hitposition,hit,hitmaterial)
					tween(fadeTime, leftprint, {Transparency = 1}, "Linear", "Out", false)
					debris:AddItem(leftprint, fadeTime*2)
				end
			end
			task.wait(frequency)
		end
	end
end)

and the server looks like this

–#Services

local players = game:GetService(“Players”)

local serverScriptService = game:GetService(“ServerScriptService”)

local replicatedStorage = game:GetService(“ReplicatedStorage”)

–#Instances

local remote = Instance.new(“RemoteEvent”)

local folder = Instance.new(“Folder”)

local walkingremote = Instance.new(“RemoteEvent”)

–#Setup

script.Parent = serverScriptService

folder.Parent = replicatedStorage

remote.Parent = folder

folder.Name = “Footsteps”

remote.Name = “FootstepsEvent”

walkingremote.Parent = folder

walkingremote.Name = “WalkingRemote”

script.FootstepsConfig.Parent = folder

local workspacefolder = Instance.new(“Folder”,workspace)

workspacefolder.Name = “FootprintFolder”

game.Players.PlayerAdded:Connect(function(plr)

plr.CharacterAdded:Connect(function(char)

repeat wait() until char and folder.FootstepsConfig

local viewOthersPrints = folder.FootstepsConfig.ViewOtherPrints

if viewOthersPrints.Value == true then

remote:FireAllClients(char)

else

remote:FireClient(plr,char)

end

end)

end)

walkingremote.OnServerEvent:Connect(function(plr,movement)

local char = plr.Character

char.Humanoid:Move(movement)

end)

there is a footprint part inside the client

my problem is when I die the footsteps I had remain heres what that looks like
image

I would love some help with this issue!

1 Like

You can create an event listener for when the player dies, and delete all of the footprints in the folder when they do. (this is a local script)

local plr = game.Players.LocalPlayer -- the local player
local footPrintsFolder = game.Workspace.footprints -- folder where the footprints are

function clearOnDeath(char)
  char:WaitForChild("Humanoid").Died:Wait() -- wait for the player to die
  footPrintsFolder:ClearAllChildren() -- get rid of all footprints when player dies
end

clearOnDeath(plr.Character) -- run the function once because the character has already spawned in when the local script is run

plr.CharacterAdded:Connect(function(char) -- wait for the player to die again each time they spawn
  clearOnDeath(char) -- send the new character to the function
end)

Alright thank you for the reply Ill check this out.

1 Like

Where Would I put this script?

in the local script you showed on here

1 Like

Its still doing it, The client script is inside starter player scripts

put a print() inside of the clearOnDeath() function after the :Wait() to check if it is running

Sorry about the late response my internet went out. This error occurred

1 Like

in the parameter of the function clearondeath you should put plr.Character or plr.CharacterAdded:Wait but of course you must first do it in a variable I think

1 Like

This got rid of the error but the footprints are still there and it did also print but didnt do anything
image

i think this might be because the script is inside the starterplayerscripts, so when the player dies it doesnt get rid of it on the player because it only got rid of it on the old player

1 Like

also if it is a local script im pretty sure the footprints will stay for the other players aswell.

I recommend that instead of eliminating them in this way, you should do it with a for cycle while you wait for a better answer, while this issue is not solved. also i didn’t make the code

oh you have a great advantage, in the function clearondeath sends a remote event to the server, then when it detects the event the server uses task.spawn so that when the player dies with a for cycle it eliminates all the children, as the server has great capacity, it will not create delay when eliminating them, if you need help with the code, look at youtube.

so you want me to make a remoteevent for the client that sends to the server script and which then the server script deletes all the children?

sorta like this ?

local plr = game.Players.LocalPlayer – the local player

local footPrintsFolder = game.Workspace:WaitForChild(“FootprintFolder”) – folder where the footprints are

local char = plr.Character or plr.CharacterAdded:Wait()

local death = game.ReplicatedStorage.Death

function clearOnDeath()

print(“yo mama”)

death:FireServer()

char:WaitForChild(“Humanoid”).Died:Wait() – wait for the player to die

footPrintsFolder:ClearAllChildren() – get rid of all footprints when player dies

end

clearOnDeath(plr.Character) – run the function once because the character has already spawned in when the local script is run

plr.CharacterAdded:Connect(function(char) – wait for the player to die again each time they spawn

clearOnDeath(char) – send the new character to the function

end)

yes but it eliminates the steps from the server

not the client i see yeah now what would i do?

the footprints are deletd on the server but not the client

hand you know about your system if you want to delete in the client then aslo I will not hit you for that.