Checking if player is in group

Hi. I’m working on a game where I want to give a player a bloxy cola if they’re in the group. It’s not working. Nothing is getting printed into the output and nobody gets a bloxy cola.

game:GetService("Players").PlayerAdded:Connect(function(player)
	if player:IsInGroup(9272318) then
		print(player.Name.." is in group!")
		local bloxyclone = script.Parent:Clone()
		bloxyclone.Parent = player.Backpack
	else
		print(player.Name.." isn't in group :(")
	end
end)

I have looked for a solution over the devforum, google and youtube with no luck. Any help would be appreciated! :slight_smile:

1 Like

I don’t seem to see a problem with the script. Can you show the hierarchy of the Script in the game’s Explorer?

image

Scripts in ServerStorage will not run. Try placing the group script in ServerScriptService, and replace the variables of the BloxyCola:

local bloxyclone = game.ServerStorage:Clone()
bloxyclone.Parent = player.Backpack

You should put the script in serverScriptService so when multiple players join there won’t be multiple bloxy colas in the same player’s inventory

It wasn’t in serverstorage. It was in ReplicatedStorage. I altered the script and moved it to ServerScriptService:

game:GetService("Players").PlayerAdded:Connect(function(player)
	if player:IsInGroup(9272318) then
		print(player.Name.." is in group!")
		local bloxyclone = game.ReplicatedStorage.BloxyCola:Clone()
		bloxyclone.Parent = player.Backpack
	else
		print(player.Name.." isn't in group :(")
	end
end)

The output now says I’m in the group but I never get the item.

I’ll give you a hint.

Are you sure the BloxyCola is still at ReplicatedStorage?

Scripts and LocalScripts won’t run in ReplicatedStorage or ServerStorage. They must be placed in other suitable locations like StarterPlayerScripts or ServerScriptService for proper execution.

You can still put your ModuleScript here. However, I believe that we must keep all server-sided code in the ServerScriptStorage, all client-sided code in StarterPlayerScripts and all shared code in ReplicatedStorage.

It allows a better organization since all codes are classed depending on their execution context.

Is the model correctly clone? Can you find it in the Explorer?
If it’s not the case, are there any errors?

With the information I can see, I’ll try and help.

Firstly, move the “Groupscript” script into the “ServerScriptService”.
Secondly, move the “BloxyCola” tool inside the “Groupscript” script.
Thirdly, copy and paste the following code inside the “Groupscript” script and it should work.

game:GetService("Players").PlayerAdded:Connect(function(player)
	if player:IsInGroup(9272318) then
		print(player.Name.." is in group!")
		local bloxyclone = script.BloxyCola:Clone()
		bloxyclone.Parent = player.Backpack
	else
		print(player.Name.." isn't in group :(")
	end
end)

You can get the model by doing script.Parent since your Script is a child of your Bloxy Cola.

So try to change how you clone your model by using script.Parent.

@ItzMeZeus_IGotHacked not rlly sure what you’re saying lol

@ZayerRBX Yeah the script is in serverscript service currently and it’s not working. The script is running, but the cola isn’t getting cloned. Also, the script is no longer a child of the cola.

I think because the tool is in ReplicatedStorage, the message on it having to be cloned has to be conveyed through a RemoteEvent. To save time, how about we:

  1. Place the Cola in ServerStorage.
  2. Place the Group Script in ServerScriptService.

And for the script, we write:

local ss = game:GetSevice(“ServerStorage”)
local cola = ss:FindFirstChild(“BloxyCola”)
game:GetService("Players").PlayerAdded:Connect(function(player)
	if player:IsInGroup(9272318) then
		print(player.Name.." is in group!")
		local bloxyclone = cola:Clone()
		bloxyclone.Parent = player.Backpack
	else
		print(player.Name.." isn't in group :(")
	end
end)
2 Likes

Same thing is happening. I have triple checked the parents of every single object. No errors. Output is saying I’m in the group. I tried parenting the cloned cola to workspace to see if it appeared there. It doesn’t, so I know it has something to do with the cloning of the item.

Can you try equipping the item on the start of the game? Parent BloxyCola to StarterPack and see if your backpack has the BloxyCola.

2 Likes

Just put it in starterpack and I am holding the item.

At this point, I think it’s an external Script that’s interfering. You might want to look around for potential scripts and see if they modify the Player’s backpack?

1 Like

Try to print out the cloned BloxyCola.Parent in the output after you clone it. Then print out the parent again after you parent it to the player’s backpack in the script. Show us the output.

1 Like

image
print(bloxyclone.Parent)

I don’t think it’s an external script simply because I have a gamepass that gives a gravity coil and it works fine.

Found the issue. Looks like the event you’re using is wrong. You can check out this post to understand why. They have a similar problem as well and it was solved.

2 Likes