#Connecting a function to when a player joins the game, What is the thing called

1 messages · Page 1 of 1 (latest)

static pumice
#

What goes where the hashtags are?

LocalPlayer.####:connect(OnJoin)

sage wren
#

dont do it like that

#

@static pumice

dim anvil
sage wren
#
Players = players:GetService("Players")
Players.PlayerAdded:connect(function(player)

whatever hjere

end) ```
static pumice
#

Thanks guys.

#

I worked it out when I posted it XD

sage wren
#

W

static pumice
#

Why won't their shirt and pants change?

#
local player = game:GetService("Players")
local LPlayer = player.LocalPlayer
local Team = LPlayer.Team

local Rank = LPlayer:GetRankInGroup(1)
local Staff_Team_Ranks = {"24", "22", "22"}
local Supervision_Team_Ranks = {"", "", ""}
local Corporate_Team_Ranks = {"", "", ""}

function OnJoined(player)
    if Rank == Staff_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Staff")
        LPlayer:FindFirstChildOfClass("Shirt").ShirtTemplate = "rbxassetid://80018832805363"
        LPlayer:FindFirstChildOfClass("Pants").PantsTemplate = "rbxassetid://95282531461583"
    end
    if Rank == Supervision_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Supervision Team")
    end
    if Rank == Corporate_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Corporate Team")
    end
end

player.PlayerAdded:Connect(OnJoined)```
sage wren
#

ok first

#

the function

#

why do you define the function then call it when they join

#

you can do it all in one block

static pumice
#

Wait

stiff pantherBOT
#

studio** You are now Level 5! **studio

sage wren
static pumice
#

Yes

sage wren
#

where

static pumice
#

workspace rn

sage wren
#

put it in starter player scripts

static pumice
#

player.PlayerAdded:Connect(function(OnJoined) Would that work instead?

sage wren
#

no

#

ill give

#
player.PlayerAdded:Connect(function(player(
    if Rank == Staff_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Staff")
        LPlayer:FindFirstChildOfClass("Shirt").ShirtTemplate = "rbxassetid://80018832805363"
        LPlayer:FindFirstChildOfClass("Pants").PantsTemplate = "rbxassetid://95282531461583"
    end
    if Rank == Supervision_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Supervision Team")
    end
    if Rank == Corporate_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Corporate Team")
    end
end
#

@static pumice

static pumice
#

Thank you"

sage wren
#

it prob wont work now

#

but check

static pumice
#

Outfit didn't change

sage wren
#

any errors?

static pumice
#

nope

sage wren
#

ok

#

so

#

where is the rank

#

where does it get their rank from

static pumice
#

Oh shit

#

I forgot to put it in there

#

I believe

#

Hold up

#

Teaming part is working

#

It's just the clothing now.

sage wren
#

ok

#

what errors

static pumice
#

Noerrors at all

sage wren
#

send new script

static pumice
#

It's the exact same as before

sage wren
#

how

stiff pantherBOT
#

studio** You are now Level 2! **studio

sage wren
#

if you fixed it

#

it will be different

static pumice
#

Wait

#

I am now testing it to see if I fixed it

sage wren
#

ok

static pumice
#
local player = game:GetService("Players")
local LPlayer = player.LocalPlayer
local Team = LPlayer.Team

local Rank = LPlayer:GetRankInGroup(35153508)
local Staff_Team_Ranks = {"255", "224", ""}
local Supervision_Team_Ranks = {"", "", ""}
local Corporate_Team_Ranks = {"", "", ""}

player.PlayerAdded:Connect(function(player)
    if Rank == Staff_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Staff")
        LPlayer:FindFirstChildOfClass("Shirt").ShirtTemplate = "rbxassetid://80018832805363"
        LPlayer:FindFirstChildOfClass("Pants").PantsTemplate = "rbxassetid://95282531461583"
    end
    if Rank == Supervision_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Supervision Team")
    end
    if Rank == Corporate_Team_Ranks then
        LPlayer.Team = game.Teams:FindFirstChild("Corporate Team")
    end
end)
#

That's the Script.

#

FYI: It didn't work

sage wren
#

Ok so

#

you have rank

#

which is a integer

#

and comparing it to values in an array like staff_team_ranks

#

which contains them is a string

#

so it wont work

static pumice
#

Ok

#

Is that were the I: v stuff comes in

#

Tables I think it's called.

sage wren
#

yea

static pumice
#

One sec

#
for _, v in pairs(Staff_Team_Ranks .. Supervision_Team_Ranks .. Corporate_Team_Ranks) do```
#

Like that?

static pumice
# sage wren yea
player.PlayerAdded:Connect(function(player)
    for _, v in pairs(Staff_Team_Ranks) do
        if Rank == v then
            LPlayer.Team = game.Teams:FindFirstChild("Staff")
            LPlayer:FindFirstChildOfClass("Shirt").ShirtTemplate = "rbxassetid://80018832805363"
            LPlayer:FindFirstChildOfClass("Pants").PantsTemplate = "rbxassetid://95282531461583"
        end
        if Rank == Supervision_Team_Ranks then
            LPlayer.Team = game.Teams:FindFirstChild("Supervision Team")
        end
        if Rank == Corporate_Team_Ranks then
            LPlayer.Team = game.Teams:FindFirstChild("Corporate Team")
        end
    end
end)

Is that correct?

sage wren
#

and it should work

#

and the id is too long i think

#

you might just need the id not the rbxassetid://

#

@static pumice

static pumice
mint saddle
#

if you change something in a localscript, unless thats replicated it wont show up for others

#

heres a fixed script btw

local function removeClothing(character)
  for _, v in character:GetChildren() do
    if v:IsA("Clothing") then v:Destroy() end  
  end  
end

game:GetService("Players").PlayerAdded:Connect(function(player)
  local rank = player:GetRankInGroup(35153508)

  if rank == some_rank then
    player.Team = some_team
  elseif rank == some_other_rank then
    player.Team = some_other_team
  end

  player.CharacterAppearanceLoaded:Connect(function(character)
    removeClothing(character)
    -- now apply custom clothing, probably by storing it in ServerStorage then cloning and parenting to character
  end)
end)
#

obviously its not fully done but you get the idea

static pumice
#

Local or normal script

mint saddle
#

normal

#

did you read what i said

#

😭

mint saddle
#

you cant change teams in local scripts

#

neither shirts templates

#

(properly)

#

because that will only show up for you

#

and you probably want everyone see your new shirt

static pumice
#

Aaah

#

When Im back on my PC, I’ll test it

#

And sort it out

mint saddle
#

in your another topic people already answered you i think

static pumice
#

They did but made no sense so

#

Then someone was being a rude bitch sooooo I gsve up

mint saddle