I’m trying to add a script that gives the server owner items upon joining the game but I have no clue on how to that (I am a beginner btw)
I’ve done plenty of research but haven’t found anything of use. I’ve figured out how to detect the server owner joining the game but am struggling to figure how to get the tool in the players backpack
Here’s the code I’ve been trying to use
local ownerId = game.CreatorId
game.Players.PlayerAdded:Connect(function(player)
if player.UserId == ownerId then
local g = game.ServerStorage.Tool:Clone()
g.Parent = player.Backpack
end
end)
The code is not exactly working because you need to be aware of that the character is not added before player joins. So you should use CharacterAdded event on player.
Furthermore, you can use CharacterAdded event connection to consistently keep a tool even after death.
I completely agree with @anon81993163, you must check that the player character has been successfully added.
Here’s the script:
local ownerId = game.CreatorId
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
if player.UserId == ownerId then
local g = game.ServerStorage.Tool:Clone()
g.Parent = player.Backpack
end
end)
end)