What do you want to achieve? Making the script assign an attribute to a character when they join the game.
What is the issue? When I run the script in Studio line 4-16 get skipped.
What solutions have you tried so far? I have tried using the AI which did not fix my issue.
I am pretty new to scripting so if it is a very dumb mistake let me know,
local Players = game:GetService("Players")
print("Test1")
local function onPlayerAdded(Player)
print("Test2")
if Player:IsInGroup(17326955) then
print("Test3")
Player:SetAttribute("IsInGOC", true)
print("Player in GOC")
local rank = Player:GetRankInGroup(17326955)
Player:SetAttribute("GOCRank", rank)
else
Player:SetAttribute("IsInGOC", false)
print("Player not in GOC")
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
print("GOC Main Group Membership Check Complete")
Just copy and pasted the script into studio and it seems to be working fine for me, your script is probably (for some reason) not running fast enough so the player loads in before playeradded has the chance to even fire, try publishing the game and have a friend or alt account join and monitor the dev console to see if the statements print.
I see the issue then, so yeah the script isn’t loading fast enough for playeradded to be able to fire, I would recommend putting this in a normal script in serverscriptservice to fix the issue.
I understand the confusion, the server can do what you want perfectly fine and it should honestly, theres no need to have it in a localscript under StarterCharacter.
not really, cause you could join before the wait is finished but the problem here is that he’s got it in a local script under starter character (i did not read the whole question)
local Player = game:GetService("Players").LocalPlayer
print("Test1")
local function onPlayerAdded(Player)
print("Test2")
if Player:IsInGroup(17326955) then
print("Test3")
Player:SetAttribute("IsInGOC", true)
print("Player in GOC")
local rank = Player:GetRankInGroup(17326955)
Player:SetAttribute("GOCRank", rank)
else
Player:SetAttribute("IsInGOC", false)
print("Player not in GOC")
end
end
onPlayerAdded(Player)
print("GOC Main Group Membership Check Complete")
local Players = game:GetService("Players")
print("Test1")
local function onPlayerAdded(Player)
print("Test2")
if Player:IsInGroup(17326955) then
print("Test3")
Player:SetAttribute("IsInGOC", true)
print("Player in GOC")
local rank = Player:GetRankInGroup(17326955)
Player:SetAttribute("GOCRank", rank)
else
Player:SetAttribute("IsInGOC", false)
print("Player not in GOC")
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, Player in Players:GetPlayers() do onPlayerAdded(Player) end
print("GOC Main Group Membership Check Complete")
If it doesn’t work then there must be something else that preventing the script from working