#how do i make PlayerAdded event loop on a character respawning after reset?

32 messages · Page 1 of 1 (latest)

eager moat
#

i have this short line of code that runs when a player joins the game but it doesnt work when a player resets & respawns
how would i make it loop to work that way?

player.PlayerAdded:Connect(function(player)
    wait(0.1)
    player.CharacterAdded:Wait()
    CatSwap(player)
end)
solid vapor
#

Mm let me see

somber roost
#

use an event to check if CharacterAdded fired

#

which will fire every time the player gets a new character e.g. after he respawns

solid vapor
#

My bad

somber roost
#

I'm ignoring the fact that he isn't using task.wait()

solid vapor
#

Oh

somber roost
#

oh wait hang on

#

I didn't actually read the character, no connect it to a function

#

then it will actually fire multiple times, and actually takes the stack back to that line

#

now it just yields the stack

solid vapor
#

Wdym?

#

@somber roost

somber roost
#

if you connect the event to a function then it will play said function every time the event fires

#

but event:Wait() yields a stack until the event is fired, so if the event fires again then the stack won't move back

eager moat
somber roost
#

Wait what?

eager moat
#

orrr oh wait i think i get it

#

i misunderstood

eager moat
# somber roost if you connect the event to a function then it will play said function every tim...

are you saying to put the PlayerAdded event into my CatSwap function like this? bit confused but here is the whole thing i adjusted some things

local rs = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Catcolors = rs.catcolors

local function CatSwap(player)
    players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Wait()
    wait(0.5)
    local originalcolors = player.Character:FindFirstChildWhichIsA("BodyColors")
    local originalshirt = player.Character:FindFirstChildWhichIsA("Shirt")
    local originalpants = player.Character:FindFirstChildWhichIsA("Pants")
    local originalface = player.Character:FindFirstChild("Head")
    wait(0.5)
    -- bodycolors
    originalcolors:Destroy()
    local newcolors = Catcolors:Clone()
    newcolors.Parent = player.Character
    wait(0.5)
    --shirt & pants
    originalshirt.ShirtTemplate = 0
    originalpants.PantsTemplate = 0
    wait(0.5)
    -- face
        originalface.face.Texture = "http://www.roblox.com/asset/?id=15431991"
    end)
end


players.PlayerAdded:Connect(function(player)
    wait(0.1)
    CatSwap(player)
end)
somber roost
eager moat
#

its not too deep its just replacing some things on the character

somber roost
#

so PlayerAdded > function > PlayerAdded

#
players.PlayerAdded:Connect(function(plr)
  plr.CharacterAdded:Connect(function()
    --all the code code inside CatSwap except for the first 2 lines
  end)
end
#

why do you not just have it like that?

eager moat
#

also i had catswap as a local function bc i was told functions are supposed to pack lines of code into one string

#

oooh wait it works now

#

i had to delete the first 3 lines not the first 2

somber roost
#

with first 2 lines I meant

players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Wait()

which are the first lines of the function

#

anyways, is it solved now @eager moat ?

eager moat
#

yea yea i got it working now tyty