Footprint - Basic implemented footprint system

Hi everyone! This is the second post on my account.

Introducing Footprint, a basic footprint system that utilizes a ParticleEmitter.

How to Use:

  1. You need a script, a player, and a ParticleEmitter.
  2. Simply require the module and follow the setup.
  3. That’s it. Now you have an very basic footprint attached to your legs!

This script serves as an equipment module, enabling a footprint trail system.

local CollectionService = game:GetService("CollectionService")
local system = {}

function system.new(
	ParticleEmitter: ParticleEmitter,
	name: string
)
    local __template = {}
	local base = setmetatable({}, {__index = __template})

	base.BaseParticle = {ParticleEmitter = ParticleEmitter}
	export type BaseParticleConfiguration = typeof(base.BaseParticle)

	local Specifiedtag = name

    --[[ 
    Assigns the footprint particle to the player.
    ]]
	function base:Assign(player: Player)
		local character = player.Character
		if not character then return end

		local leg = character:FindFirstChild("HumanoidRootPart")
		if not leg then error("Cannot find the specified leg in the player model!") else print("at") end

		local Attachment = Instance.new("Attachment")
		Attachment.Name = name
		Attachment.Parent = leg
		Attachment.Position = Vector3.new(0,-3,0)
		CollectionService:AddTag(Attachment, Specifiedtag)

		local particle = base.BaseParticle.ParticleEmitter:Clone()
		particle.Enabled = false
		particle.Parent = Attachment

		local humanoid = character:FindFirstChildOfClass("Humanoid")
		if not humanoid then return end

		humanoid.Running:Connect(function(speed: number) 
			if speed > 0 then
				print("nig")
				particle.Enabled = true
			else
				particle.Enabled = false
			end
		end)
	end

    --[[ 
    Remove the footprint particle from the player. Does not remove anything IF there is no assigned footprint particle with the specified name.
    ]]
	function base:Remove(player: Player, name: string)
		for _, v in pairs(player:GetDescendants()) do
			if CollectionService:HasTag(v, Specifiedtag) and v.Name == name then
				v:Destroy()
			end
		end
	end

	return base
end

export type FootprintEquipment = typeof(system.new(...))
return system
6 Likes

I like the fact that it is OOP but you should probably not put the functions inside the object itself as this will start to use up a lot of memory, use the index method.

4 Likes

Thanks for your reply, but on this case what should I do with it then?
Since its the only case to do it without glitching functions on the table base. If there is an laternate method for the function to not appearing on the main base script, I would be very appreciated!

3 Likes

Wait, I didn’t understand how does it work. Is it like Minecraft sprint particles or is it an actual footprint??? Because I may be stupid, but particle emitter is not… for a static object, right…?

mini world footprint reference. made it in case for people needs to have a footprint system

3 Likes

Oh… Alright then! That ParticleEmitter part was so confusing for me. I would recommend including screenshots in your posts to prevent people like me ask you these questions!

image
okay,so first we have ParticleEmitter as example… We put that onto the input, and then the Engine will create an Attachment with the cloned ParticleEmitter into the attachment,and Attachs it into the Root part of the player (formely HumanoidRootPart), add offsets,and now it works just like that.
When the player start walking, the particle attached will enable. When stopped,it would automically disable.

3 Likes

Actually I am not sure now that I look at it again, I am not very familar with export and I don’t know if using the index method could break your code.

In that case, maybe can this work aswell?

local base = setmetatable({}, {__index = self})

Index method sure breaks my code, so I need an other approach…

In this case it would be __index = system, and you’d move the class methods outside of the constructor

Maybe instead of doing this, I already modified the case of the __index, which do this:

local __tempoary = {}
local base = setmetatable({}, {__index = __tempoary})

As this keeps the function doesnt over outside the range of the script so that can be handled easily. Maybe.

Export is just to export the type name with the datas.
I used typeof to make sure the functions and the datas are maintained on the type. But since when exporting a type,their data template is constant, so I can only export it in global after the function.

interesting debug print you got there

2 Likes

I’ve been on Roblox for 3.5 years and never actually knew what export did, I did a bit of research, and it seems to be for telling the type checker to treat your module as actual classes or data types as far as I could understand.

Very cool.

2 Likes