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

Trying to give myself a needle gun when i join my game Can anybody help me?

This is the code, i works on studio but not in game, I DO have API on

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == "Pipe_Gamerz" then
         local Potato = game.ReplicatedStorage.Needlegun:Clone()
        Potato.Parent = game.Players.Pipe_Gamerz.Backpack
        local Potato2 = game.ReplicatedStorage.Needlegun:Clone()
        Potato2.Parent = game.Players.Pipe_Gamerz.StarterGear
    end
end)

Help is extremely appreciated

1 comment

0

remove the Local from your variables

2 answers

So It seems a lot of people have problems using Players, so Im guessing that is is deprecated. use this instead:

local function giveTool(player, tool) -- easier and removes the chance for failure
	local backpack = player:FindFirstChildOfClass("Backpack")
	if backpack then
		tool.Parent = backpack
	end
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
    if plr.Name == "Pipe_Gamerz" then
	print("Test")
         local Potato = game.ReplicatedStorage.Needlegun:Clone()
	giveTool("Pipe_Gamerz", Potato)
        local Potato2 = game.ReplicatedStorage.Needlegun:Clone()
	giveTool("Pipe_Gamerz", Potato2)
    end
end)

This will probably work

local target = "Pipe_Gamerz" -- name
game.Players.PlayerAdded:Connect(function(plr)) -- check if a player joined
	if plr.Name == target then -- if the player joined's name is target's name then
		print(target.." Found in the server. giving "..target.." the tool.") -- print that we found the player you can remove it
		local toolClone = game.ReplicatedStorage.MyTool:Clone() -- make a clone so whenever you join the server again it gives you the tool again
		toolClone.Parent = plr.Character -- for making him hold it instantly
		-- toolClone.Parent = plr.Backpack -- for adding it to his inventory without holding it
	else -- if the player name isn't the target's name then
		print("Target was not "..target.." skipping.") -- print that the player was not the player we are looking for
	end -- ends 'if plr.Name == target then'
end) -- ends 'game.Players.PlayerAdded:Connect(function(plr))'

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