Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by
Torren_Mr 334 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
doesn't work after that at all, even if you start the game, it just wont create any trail anymore digameschannel 44 — 4y
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. Torren_Mr 334 — 4y
0
what you expected, you inserted player.CharacterAdded:Connect into PlayerAdded, :Connect must be outside of the function as i know digameschannel 44 — 4y
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? Torren_Mr 334 — 4y
View all comments (21 more)
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. Torren_Mr 334 — 4y
0
it doesnt need second attachment, it creates when you choice location digameschannel 44 — 4y
0
it doesnt need second attachment, it creates when you choice location digameschannel 44 — 4y
0
Well, the script works now and it didn't work without the second attachment. Torren_Mr 334 — 4y
0
the scriprt just creates line that gives you lead to the hotel or other location digameschannel 44 — 4y
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. Torren_Mr 334 — 4y
0
i edited my post so you can see local script of the button digameschannel 44 — 4y
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) Torren_Mr 334 — 4y
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 digameschannel 44 — 4y
0
It doesn't matter where the script is. Is your game R6 or R15? Torren_Mr 334 — 4y
0
by the way, the parent of char gives nil, means it doesnt searches for workspace character digameschannel 44 — 4y
0
r15 digameschannel 44 — 4y
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. Torren_Mr 334 — 4y
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 digameschannel 44 — 4y
0
Wait what second local t? Torren_Mr 334 — 4y
0
local a* you did 2 local a's digameschannel 44 — 4y
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. Torren_Mr 334 — 4y
0
Right, the first local a is the wrong one, you need to keep the second, I will edit my answer, copy it again. Torren_Mr 334 — 4y
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 digameschannel 44 — 4y
0
You can send me the codes you have currently in discord. [CLASSIFIED]#9999 so I can have a look. Torren_Mr 334 — 4y
0
k, ill do this tommorow digameschannel 44 — 4y
Ad

Answer this question