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)
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)