Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I give a certain player a tool when they join the game?

I'm looking for a way to give myself a tool upon joining the game, I tried some code however it hasn't done anything so far, and no errors are turning up in the developer console.

This is my script.

local g = game.Lighting.Tool:Clone()

game.Players.PlayerAdded:Connect(function(plr)
	if plr.Name == "ZenRBXImagineer" then
		g.Parent = game.Players.ZenRBXImagineer.Backpack
	end
end)

Some help would be appreciated. Thanks!

2 comments

0

Dont use lighting for storage

0

What type of script is it and where is the script placed?

2 answers

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.

1 comment

0

Hey, I know that this was from 2 years ago but could you please post respawn item code o.o?

try replacing playeradded with humanoid.died

game.Players.Humanoid.died: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)

This discussion is preserved as it was. New answers, comments, and votes are closed.