So firstly, it's probably better to place your tool into ServerStorage, but besides that, the main concern with your code is that the tool will not load into the player if there is no character. With this in mind, you can use the following code:
game.Players.PlayerAdded:Connect(function(plr)
local character = game.Workspace:WaitForChild(plr.Name)
if plr.Name == "ZenRBXImagineer" then
local g = game.ServerStorage.Tool:Clone()
g.Parent = plr.Backpack
end
end)
If you insist on using the Lighting in Workspace, you can do this:
game.Players.PlayerAdded:Connect(function(plr)
local character = game.Workspace:WaitForChild(plr.Name)
if plr.Name == "ZenRBXImagineer" then
local g = game.Lighting.Tool:Clone()
g.Parent = plr.Backpack
end
end)
you'll notice the main alteration is line 2, which waits for the character of the player to load, this is necessary since the Tools when placed into the player's backpack will be moved to the player's Character.
This code should be placed in a Script within ServerScriptService
Warning: I will note that neither this code nor the one you put up earlier will respawn the item if you reset or die. If you want that information, just comment on the post and I'll add that.
2 comments
Dont use lighting for storage
What type of script is it and where is the script placed?