I am trying to give players items when they join, but it won’t work.
Here is my original script:
game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(11635716) >= 2 then
local mop = game.ServerStorage.Items.Mop
local mopCopy = mop:Clone()
mopCopy.Parent = plr:WaitForChild("Backpack")
end
end)
That didn’t work, but it didn’t show any errors, so I tried this:
Server:
game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(11635716) >= 2 then
game.ReplicatedStorage.FireItems.FireMop:FireClient(plr)
end
end)
Client:
local mop = game.ReplicatedStorage.Mop
game.ReplicatedStorage.FireItems.FireMop.OnClientEvent:Connect(function(plr)
local mopcopy = mop:Clone()
mopcopy.Parent = plr:WaitForChild("Backpack")
end)
The new error is that it is attempting to index nil with wait for child. I changed the location of the item after the first script didn’t work, so instead of server storage, it was in replicated storage. How do I fix this?
Oh I figured out the issue. The player wasn’t fully loaded in, so it wouldn’t work. I just added a wait statement, so it worked, but is there a way where it would just wait until the player was fully loaded in instead of waiting a set amount of time?
Try to add this in the Server Script part, right before the GetRankInGroup line:
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait() --If player.Character is nil then it will wait for CharacterAdded event to fire because of :Wait()
Sorry for any weird format, not on my PC rn. Let me know if it works
Edit: If it doesnt work you can try this too:
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait() --If player.Character is nil then it will wait for CharacterAdded event to fire because of :Wait()
local humanoid = character:WaitForChild("Humanoid")
if humanoid then
--Put the rest of your server script here and add another end at the end.