The function Playeradded isn't working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello, I made a script where if a player join the game, they will send a random tool to their backpack
  2. What is the issue? Include screenshots / videos if possible!
    The Playedadded function isn’t working, if I remove it, It works
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    yes

Local Script:

local event = game.ReplicatedStorage.GetPlayerEvent2
local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(plr)
	if player.Name == plr.Name then
event:FireServer(player)
	end
end)

Script:

local RandomTool = game.ReplicatedStorage.Tools:GetChildren()[math.random(1, #game.ReplicatedStorage.Tools:GetChildren())]
event.OnServerEvent:Connect(function(player)
	RandomTool.Parent = player.Backpack
end)

Remove the localscript, and change the server script to this

game.Players.PlayerAdded:Connect(function(player)
local RandomTool = game.ReplicatedStorage.Tools:GetChildren()[math.random(1, #game.ReplicatedStorage.Tools:GetChildren())]:Clone()
	RandomTool.Parent = player.Backpack

end)

It isn’t working. I don’t receive the item.

Okay then share the output, i can’t magically see what happens on your computer. Maybe you don’t have a folder named tools in replicated storage, or you put the script into a wrong place


And I have no errors in the output.

This is the error I got when I reset myself ^^
I don’t have any other errors.

game.Players.PlayerAdded:Connect(function(player)
	local RandomTool = game.ReplicatedStorage.Tools:GetChildren()[math.random(1, #game.ReplicatedStorage.Tools:GetChildren())]:Clone()
	player.CharacterAdded:Wait()
	RandomTool.Parent = player.Backpack
end)

Try this

1 Like

Thank you so much, you solved two of my errors.
:blush:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.