So I just built this big block of code probably the biggest I have ever done and I was wondering why exactly the script was stopping at the point of saying that I wasn’t in the group, after checking 1 time per second for 10 seconds.
I think it’s the game.Players.PlayerAdded:Connect(function(newPlayer) area but I’m unsure of how to fix it.
Can someone please explain why the following code is only getting that far?
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ChillRemoteEvent")
local Chill = false
local inGroup = false
print("Starting first check")
while true do
wait(1)
if game.StarterGui.Chill.Enabled==true then
Chill=true
print("Checked to see if Chill page was open, was")
break
end
print("UI Check loop has been broken, moving on")
end
print("Starting check to see if player is in group")
game.Players.PlayerAdded:Connect(function(newPlayer)
if newPlayer:IsInGroup(6967967) then
print ("Player is in Weird Games, Inc.!" )
inGroup = true
else
print("First check to see if player was in group failed. Trying 10 times, once every second, to see if they are really in the group")
for count = 1,10,1 do
wait(1)
if newPlayer:IsInGroup(6967967) then
print ("Player is in Weird Games, Inc.!" )
inGroup = true
end
end
end
end)
if inGroup == false then
print("Player is not in group, check will not continue")
else if inGroup == true then
print("Player is in the group, moving on...")
else
print("A really weird error has occurred.")
end
end
if inGroup == true then
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local face = character:WaitForChild("Head"):WaitForChild("face")
if face:IsA("Decal") then-- if it's a valid face, then...
if face.Texture == "http://www.roblox.com/asset/?id=7074749" then
print("Player is wearing Chill Face! Switching over to server script to handle role-changing...")
remoteEvent:FireServer()
end
end
end
Thanks for all the help, I believe this is just a small error
I think it’s because your line, the script reads it and returns it before the server has time to react to the player that joined the game. If you add your “If inGroup” statements in playeradded, that might solve the issue but I’m not 1000% sure of it.
Basically i think the problem is the “while true do”, since the loop is infinite, so the whole script after it will never work. So I recommend you put the loop at the end of the script.
Yes, but the playeradded only works when the player has just been added. So the playeradded doesn’t work as it waits for the loop to be broken, and when the playeradded event is finally created, the player has already been added so the event is not activated.
@Seikm Alright so I did what you said and it still is only printing to the part where it’s trying to see if the player is in the group. The last thing printed isStarting check to see if player is in group
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ChillRemoteEvent")
local Chill = false
local inGroup = false
print("Starting first check")
print("Starting check to see if player is in group")
game.Players.PlayerAdded:Connect(function(newPlayer)
if newPlayer:IsInGroup(6967967) then
print ("Player is in Weird Games, Inc.!" )
inGroup = true
else
print("First check to see if player was in group failed. Trying 10 times, once every second, to see if they are really in the group")
for count = 1,10,1 do
wait(1)
if newPlayer:IsInGroup(6967967) then
print ("Player is in Weird Games, Inc.!" )
inGroup = true
end
end
end
while true do
wait(1)
if game.StarterGui.Chill.Enabled==true then
Chill=true
print("Checked to see if Chill page was open, was")
break
end
print("UI Check loop has been broken, moving on")
end
if inGroup == false then
print("Player is not in group, check will not continue")
else if inGroup == true then
print("Player is in the group, moving on...")
else
print("A really weird error has occurred.")
end
end
if inGroup == true then
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local face = character:WaitForChild("Head"):WaitForChild("face")
if face:IsA("Decal") then-- if it's a valid face, then...
if face.Texture == "http://www.roblox.com/asset/?id=7074749" then
print("Player is wearing Chill Face! Switching over to server script to handle role-changing...")
remoteEvent:FireServer()
end
end
end
end)
Looking at your script again, I realized that you can use the Changed event to replace the loop. Basically the Changed event activates whenever a value is modified (More information: IntValue | Documentation - Roblox Creator Hub).