Hello, im trying to put trails to my game, but i dont know how to make them still stay when you die? Like you dont have to put it on again manually.
You can do this but change it how you want, put in ServerScriptService in a Script
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local trail = game:GetService("ReplicatedStorage").Trail:Clone()
trail.Parent = character:WaitForChild("HumanoidRootPart")
trail.Attachment0, trail.Attachment1 = character:WaitForChild("HumanoidRootPart").RootRigAttachment, character:WaitForChild("UpperTorso").BodyBackAttachment
end)
end)
This is what it looks like VIDEO
Unfortunately, you can’t. Whenever a player resets his character on Roblox, he resets his character, meaning the character is being destroyed and after the RespawnTime passes, it is being reinserted.
The only way to get over it would be to manually put it again in 2 solutions.
- Add a script in StarterCharacterScripts that is adding the trail, it will run every time the Character respawns.
- If you already have a .PlayerAdded connection, you can use player.CharacterAdded inside that function of the connection, and add the trail there.
References:
https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded
https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAdded
- Make a trail variable
- When the character dies, parent the trail to server storage
- Add a function that listens for Character Added event, check if it is not nil. If it is not nil, reparent the instance (trail) in the Humanoid Root Part, else if it is nil, return nothing.
local trail
local playerService = game:GetService("Players")
playerService.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if trail ~= nil then
trail.Parent = char:WaitForChild("HumanoidRootPart")
--Set attachments
else
return
end
char:WaitForChild("Humanoid").Died:Connect(function()
trail.Parent = game.ServerStorage
end)
end)
end)
--Define a buy trail/equip trail function that listens for an event when you get a trail via bindable events
--inside the function, define the variable trail as the current trail used by the player
Read about bindable events (if you haven’t) here: BindableEvent | Roblox Creator Documentation
Please tell me if it works (oh and this is just an example, you have to fill in the blanks yourself
)