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

How do i clone a tool to the local player backpack?

So, i made this script that is supose to check your player name and if it is the right name, it will give you a tool.

Im new a scripting btw.

Script:

--// Variables \\--
local THANOS = ('mewant_taco'/'mene_PT'/'SirLenom')
local player = game.Players.LocalPlayer
local backpack = player.Backpack 

--// Clone \\--
if player.Name == THANOS then
    local GLOVE = game.ServerStorage.SteampunkGlove:Clone()
    GLOVE.Parent = backpack
end 

Ok bye

2 comments

0

Do you use a normal script(server script) or a local script?

0

What you'll need to do is create a server script in the workspace or even "ServerScriptStorage". Then have the script wait for the event called "PlayerAdded" by using Game.Player.PlayerAdded:Connect(player). Within that event handler, you would have it check if the players name corresponds with any of the names inside the "THANOS" array. To do this, you would likely use a loop.

1 answer

✓ Accepted answer

Alright, so I was gonna do a RemoteEvent at first since you appeared to be using a LocalScript, but then I saw Stephenthefox's Comment and realized that would work better for your purposes.

Problems:

  1. Your table used division symbols, meaning it would error as if you were performing math on the string values
  2. There was a recent update on Roblox so when the Player is added you can't immediately tack on a Tool, you have to wait for the Character to load
  3. Calling a table's values requires you do go through the table, by using player.Name = THANOS you attempted to index the Table, resulting in a nil value for the names.
  4. You cannot call the Server Storage from the Client

Code:

local THANOS = {"mewant_taco", "mene_PT", "SirLenom"}

game.Players.PlayerAdded:Connect(function(player)
	game.Workspace:WaitForChild(player.Name)
	local backpack = player.Backpack
	for index = 1, #THANOS do
	    local value = THANOS[index]
	    if player.Name == value then
			local GLOVE = game.ServerStorage.SteampunkGlove:Clone()
			GLOVE.Parent = player.Backpack
		end
		wait()
	end
end)

Solutions: I edited your table to be in the proper format for this script. There is a wait function for the player's character to be loaded. The script will run through all names in the table before giving the item out. The function is based on a server-side event to call the player.

Notes: This Code MUST be run from a Script (Server-Side, NOT a LocalScript), which is best placed in the ServerScriptService.

1 comment

0

Thank you very much :3

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