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

IsInGroup() not working correctly, can anyone help?

Asked by
harstud 218 Moderation Voter
4 years ago

I'm using IsInGroup() for my game, and it isn't exactly working. Can someone help me?

game.Players.PlayerAdded:Connect(function()
    local id = 5150581
    if game.Players.LocalPlayer:IsInGroup(id) then                    
        game.Lighting:WaitForChild("Yoghurt").Parent = game.Players.LocalPlayer.Backpack   
    end
end)
0
There is no error by the way. harstud 218 — 4y
0
It just doesn't work, HTTP requests and API Services are both on. harstud 218 — 4y
0
Local script or a server script? DeveloperSolo 370 — 4y
0
its a server script since the first line is playeradded function, local scripts dont have that really since they are created for the player Gameplayer365247v2 1055 — 4y

3 answers

Log in to vote
1
Answered by
megukoo 877 Moderation Voter
4 years ago

PlayerAdded will not fire for the client that joins the game, but all other clients that join after.

You should be doing this in a server script instead. Here's some sample code:

local Players = game:GetService("Players")
local id = 5150581

Players.PlayerAdded:Connect(function(player)
    -- server will get every player that joins
    if player:IsInGroup(id) then     
    local tool = game.Lighting:WaitForChild("Yoghurt") -- i recommend you put these in ReplicatedStorage or ServerStorage, and NOT Lighting. Lighting is not meant for storage.     

    player.CharacterAdded:Connect(function(char)
        -- gives it to them every character spawn
        tool:Clone().Parent = player.Backpack   
    end)          
    end
end)
0
Oh, thanks! harstud 218 — 4y
Ad
Log in to vote
0
Answered by
0_2k 496 Moderation Voter
4 years ago

Sometimes, while Roblox runs slow the function doesn't process the variable id try just inputting the ID, if neither works then ensure HTTP Requests & API Services are enabled and if still nothing works just wait it out a bit.

Log in to vote
0
Answered by 4 years ago
local id = 5150581--we can keep this variable outside since it wont update anyway
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()--wait for the character to load so it knows who to check on, this will update every time a new character gets added instead of a new player

         if player:IsInGroup(id) then   --and here u check if they are in the group since this will get checked after the character gets added                
                game.ServerStorage:WaitForChild("Yoghurt"):Clone().Parent = player:WaitForChild("Backpack")   --if u dont clone it then it will only work once because ur not creating a duplicate, also the backpack gets deleted every time the player dies and recreated so wait for the backpack to be created too
            end
    end)
end)
0
forgot to mention, make it a server script or it wont really work properly and this is also exploit proof Gameplayer365247v2 1055 — 4y

Answer this question