Insert a trail in each body part when the player reaches a certain speed

How would i go about achieving the effect of a player, walking, and from the moment they go faster than a certain speed they get a special trail (trail on each attachment made in bodyparts, i also dont know how to make the attachments) and when they go slower the trail dissapears again.

(this is for a The Flash game of mine.)

My current effects involve just a trail on a part you hold while running which is pretty bad and is also just 1 block of trail, having a trail on each body part would be much better.

I’m working on the script, but is your game going to be r6 or r15?

1 Like

It’s R15, thank you for your help!

Check for changes in the players speed. If the speed is higher than the threshold, use a for loop to insert the trails,
else, delete the trails from the parts of the character

1 Like

The local script would only fire once
And the part where you iterate through all of the parts of the character is rather inefficient. You should use a for loop and then check whether the instance in the character can have a trail attachment

Thats what he wants. I’m going to fix it because I have to make it when the character goes slower again.

Yes, a loop can do the trick, but you have to create separate attachments for each body part. I just said it was inefficient, if you have a better way then post it :man_shrugging:

What I mean is that the local script would only fire once, and it would fire only when the script has been added into the character by the game. That means it is not always checking the speed of the character, it only checks the speed once

I seem to have a problem where I don’t get the trail. I put WANTEDWALKSPEED as 60 and the top speed you can go is 500, I’m not sure if I have to put the WANTEDWALKSPEED exactly as the top speed or not, either way it didn’t work both ways. help?

This is the reason why nothing happens. Please read my post above. Sorry I cannot provide a script because

  1. It is against forum guidelines
  2. I’m outside

Is there a way to fix it? I’m still learning scripting so yeah…
Maybe @Fvrenight knows?

On server: in a playeradded function, check when a players characters speed has changed. After that you can carry out the necessary checks. You can also do that on the client, although you will need to make use of a remote event

Sorry if it is against the guidelines, I can’t provide a script any further, but what you can do is if you already have a speed change script, you can check the players speed either in what @Amalgamous_prime told you or constantly check through a loop.

Awh, I’m not really sure how I’m supossed to do that since I don’t really know how to script lua just yet. I’m still in the learning.

You can use the instance.Changed event or the instance:Getpropertychangedsignal. You can read more about it on Instance | Roblox Creator Documentation
Or
Instance | Roblox Creator Documentation

You can modify the code below to match your needs:

local Players = game:GetService("Players")

local trail = script.trail --trail path

local thereshold = 40 

function Set(char, state) 
	for i, part in pairs(char:GetChildren()) do 
		if not part:IsA("BasePart") then continue end 
		local found = part:FindFirstChild(trail.Name)
		if state and not found then 
			trail:Clone().Parent = part 
		elseif not state and found then 
			found:Destroy()
		end
	end
end

function PlayerAdded(player) 
	local function CharacterAdded(char) 
		local hum = char:WaitForChild("Humanoid", 5) 
		if not hum then return end 
		hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function(speed)
			if not tonumber(speed) then return end 
			if speed > thereshold then 
				Set(char, true)
			else 
				Set(char, false)
			end
		end)
	end
	CharacterAdded(player.Character or player.CharacterAdded:Wait()) 
	player.CharacterAdded:Connect(CharacterAdded)
end

for i, player in pairs(Players:GetPlayers()) do 
	PlayerAdded(player)
end
Players.PlayerAdded(PlayerAdded)
1 Like