Hi all. I’m trying to make a group join tool reward but it doesn’t seem to be cloning the tool to the players backpack.
-- Group reward --
local groupID = 6006248
local balloon = game.ReplicatedStorage:WaitForChild("Balloon")
local random = Random.new()
local hue, sat, val = random:NextNumber(),random:NextNumber(),random:NextNumber()
balloon:WaitForChild("Balloon").Color3 = random
game.Players.PlayerAdded:Connect(function(plr)
local Backpack = plr:WaitForChild("Backpack")
if plr:IsInGroup(groupID) then
balloon:Clone().Parent = Backpack
end
end)
Error:
Thanks.
Did you mean to do .Color
instead of .Color3
?
Edit: You’re also trying to set the color to a Random
object? I think you meant to use the hue, sat, val variables you have instead?
balloon:WaitForChild("Balloon").Color = Color3.fromHSV(hue, sat, val)
1 Like
If it is a mesh part, which I’m guessing, use Colour and set the colour value as Colour3.fromRGB rather than balloon.Colour3.
Setting it using Hue, Saturation and Value will require the Colour3.fromHSV
1 Like
Yes it is a part. Changed and now I get no errors but it doesn’t work:
-- Group reward --
local groupID = 6006248
local balloon = game.ReplicatedStorage:WaitForChild("Balloon")
local random = Random.new()
local hue, sat, val = random:NextNumber(),random:NextNumber(),random:NextNumber()
balloon:WaitForChild("Balloon").Color = Color3.fromHSV(hue, sat, val)
game.Players.PlayerAdded:Connect(function(plr)
local Backpack = plr:WaitForChild("Backpack")
if plr:IsInGroup(groupID) then
balloon:Clone().Parent = Backpack
end
end)
Is this in studio solo testing or Roblox Game Client?
1 Like
It is in the Studio solo testing.
Try publishing the game and play it using the Roblox game client. Possibly studio doesn’t detect groups associated on the profile.
I think what is happening is that because of the WaitForChild for changing the color, you join before the PlayerAdded event has been created.
Try this out
-- Group reward --
local groupID = 6006248
local balloon = game.ReplicatedStorage:WaitForChild("Balloon")
local random = Random.new()
local hue, sat, val = random:NextNumber(),random:NextNumber(),random:NextNumber()
balloon:WaitForChild("Balloon").Color = Color3.fromHSV(hue, sat, val)
local function onPlayerJoin(plr)
print(plr.Name)
local Backpack = plr:WaitForChild("Backpack")
if plr:IsInGroup(groupID) then
balloon:Clone().Parent = Backpack
end
end
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
onPlayerJoin(player)
end
game:GetService("Players").PlayerAdded:Connect(onPlayerJoin)
Also ensure you’re in the group with the specified id
2 Likes
Otherwise if that doesn’t work try using Embat’s idea and see if that works on game client.
Still doesn’t work, not even on game client. It even prints the players name but just won’t clone.
Can you also print out the plr:IsInGroup(groupID)
condition? It could be that it’s detecting you’re not in the group, maybe you wrote the wrong group id? Try putting the clone line outside of the if statement to see if that’s working correctly
Or I think it is cloning but because your character has not loaded in yet, once they do load in, their backpack is cleared out and then everything from StarterGear/StarterPack is cloned, try adding in a plr.CharacterAdded:Wait()
statement after the print?
1 Like
Something might be yielding the script. For debugging, maybe add print commands after each and every waitforchild or try adding an exaustion time (WaitForChild('Child', 1) --one second of waiting
1 Like
How would I print that condition?
print(plr:IsInGroup(groupID))
. But I think it may just be what I had mentioned, add a plr.CharacterAdded:Wait()
after the print(plr.Name)
so the function looks like
local function onPlayerJoin(plr)
print(plr.Name)
plr.CharacterAdded:Wait()
if plr:IsInGroup(groupID) then
balloon:Clone().Parent = plr.Backpack
end
end
1 Like
local Group = plr:IsInGroup()
print(Group) -- prints true/false
1 Like
-- Group reward --
local groupID = 6006248
local balloon = game.ReplicatedStorage:WaitForChild("Balloon")
local random = Random.new()
local hue, sat, val = random:NextNumber(),random:NextNumber(),random:NextNumber()
balloon:WaitForChild("Balloon").Color = Color3.fromHSV(hue, sat, val)
local function onPlayerJoin(plr)
print(plr.Name)
print(plr:IsInGroup(groupID))
plr.CharacterAdded:Wait()
if plr:IsInGroup(groupID) then
balloon:Clone().Parent = plr.Backpack
end
end
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
onPlayerJoin(player)
end
game:GetService("Players").PlayerAdded:Connect(onPlayerJoin)
It prints out true and all but doesn’t work weirdly.
EDIT: Checked in game, works. Thankyou.
Hmm, try also cloning to StarterGear?
local function onPlayerJoin(plr)
print(plr.Name)
print(plr:IsInGroup(groupID))
plr.CharacterAdded:Wait()
if plr:IsInGroup(groupID) then
balloon:Clone().Parent = plr.Backpack
balloon:Clone().Parent = plr.StarterGear
end
end
Although not sure if that was your original intention to have the tool stay with you even after death
1 Like
Mark any answer you think to be useful as the answer, so other people who have the same problem can easily see the answer.
1 Like