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!
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.
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)
@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:
Place the Cola in ServerStorage.
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)
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.
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?
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.
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.