Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make on respawn instance.new? It doesn't create trail when respawn

I'm making trail for GPS that parenting to torso, but there is a problem, it uses PlayerAdded. It doesn't creates trail if you die, how do i fix it?

local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	local name = player.Name
	local a = Instance.new("Attachment")
	local t = Instance.new("Trail")
	a.Parent = game.Workspace:WaitForChild(name):WaitForChild("LowerTorso")
	a.Name = "loc0"
	t.Parent = game.Workspace:WaitForChild(name):WaitForChild("LowerTorso")
	t.Name = "GPS"
	t.MaxLength = 1
	t.MinLength = 1
	t.Lifetime = 0
	t.Attachment0 = t.Parent:FindFirstChild("loc0")
end)

Script isn't local if you ask

local player = game.Players.LocalPlayer
local t = player.Character:WaitForChild("LowerTorso"):FindFirstChild("GPS")
local button = script.Parent

local function onButtonActivated()
t.Attachment1 = game.Workspace.Keypoints.Point1.loc1
end
 
button.Activated:Connect(onButtonActivated)

1 answer

✓ Accepted answer

You need to make the event detect if the player has respawned.

To do that you need to use the CharacterAdded event.

Script is below:

local Players = game:GetService("Players")

function onCharacterAdded(char)
    local t = Instance.new("Trail")
    local a = Instance.new("Attachment",char.LowerTorso)
    t.Parent = char:WaitForChild("LowerTorso")
    t.Name = "GPS"
    t.MaxLength = 1
    t.MinLength = 1
    t.Lifetime = 1
    t.Attachment0 = a
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end)
local player = game.Players.LocalPlayer
local t = player.Character:WaitForChild("LowerTorso"):FindFirstChild("GPS")
local button = script.Parent

local function onButtonActivated()
t.Attachment1 = game.Workspace.Keypoints.Point1.loc1
end

button.Activated:Connect(onButtonActivated)

25 comments

0

doesn't work after that at all, even if you start the game, it just wont create any trail anymore

0

It's doesn't work with the script you gave me too. The Attachment(loc0) and Trail(GPS) get added to the character after respawn, the trail just doesn't show, it didn't with the script you gave me too.

0

what you expected, you inserted player.CharacterAdded:Connect into PlayerAdded, :Connect must be outside of the function as i know

0

Nope, it can be inside too. The script does work as the instances get added into the character, just the trail doesn't work for some reason. Are you sure your trail does work?

0

It didn't work because the lifetime was too short and it needed 2 attachments, the script only made one. I updated my answer, try the script from my answer now.

0

it doesnt need second attachment, it creates when you choice location

0

it doesnt need second attachment, it creates when you choice location

0

Well, the script works now and it didn't work without the second attachment.

0

the scriprt just creates line that gives you lead to the hotel or other location

0

OH, I thought you wanted to make a normal trail lmao. I am not sure why the previous script didn't work because I don't have the whole script.

0

i edited my post so you can see local script of the button

0

Updated my answer again. The script does work the way it is supposed to (at least if I got what you wanted it to do)

0

where parent of script must be? cause it still doesn't creates anything inside LowerTorso, i checked out it multiple times, even after resets it still doesn't creates any trail or attachment, parent is server script service

0

It doesn't matter where the script is. Is your game R6 or R15?

0

by the way, the parent of char gives nil, means it doesnt searches for workspace character

0

r15

0

Did you copy the scripts or did you make some changes? The scripts work for me no matter where they are, they work in r15 only, and the character isn't nil for me.

0

my game is r15 only, it doesnt work, i removed second local t, added print to check if character is nil "print (char.Parent)" to see if it looks for player from workspace, not from players folder

0

Wait what second local t?

0

local a* you did 2 local a's

0

Also char doesn't really have a parent if it's found by the event. Making the script print char parent will break the whole thing.

0

Right, the first local a is the wrong one, you need to keep the second, I will edit my answer, copy it again.

0

nah still, no effect, it just doesnt create the trail and attachment, or just doesn't parents it to lower torso, no errors, just no effect

0

You can send me the codes you have currently in discord. [CLASSIFIED]#9999 so I can have a look.

0

k, ill do this tommorow

This discussion is preserved as it was. New answers, comments, and votes are closed.