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

Tool bound to character, lost on death/respawn. How to change?

I'm familiar with code but not enough to write it out as if I knew the language fluently, so I had some help creating this script for ServerScriptService:

local tools = {game.ServerStorage.VEnforcer}
local admins = {Doom10000=true}

game.Players.PlayerAdded:connect(function(p)
if admins[p.Name] then
	local backpack = p:WaitForChild("Backpack")
		for i,v in ipairs(tools) do
		v:Clone().Parent = backpack
		end
	end
end)

It allows a character to spawn with the appropriate tool assigned, but upon death, it is removed. I tried altering it to put the tool in the backpack through StarterGear but it doesn't work out.

If someone could help explain how to do this, with or without elaboration on the coding itself, would be very appreciated!

3 answers

local tools = {game.ServerStorage.VEnforcer}
local admins = {Doom10000=true}

game.Players.PlayerAdded:connect(function(p)
if admins[p.Name] then
    local backpack = p:WaitForChild("Backpack")
    p.CharacterAdded:connect(function()
    	for i,v in ipairs(tools) do
         v:Clone().Parent = backpack
	 end
      end
  end)
end)

try to see if it works this time

2 comments

0

Sorry, tool still spawns initially but is lost with death/respawn.

0

Try panthers, I forgot to add a characterAdded function.

Do this:

local tools = {game.ServerStorage.VEnforcer}
local admins = {Doom10000=true}

game.Players.PlayerAdded:connect(function(p)
if admins[p.Name] then
    local backpack = p:WaitForChild("Backpack")
	p.CharacterAdded:connect(function()
	        for i,v in ipairs(tools) do
	        v:Clone().Parent = backpack
	        end
	end
    end
end)

The character added function makes it do this everyone a player's character spawns.

10 comments

0

The code comes up with an error, stating " expected ')' (to close '(' at line 7), got 'end' " and hasn't fixed the problem -- doesn't spawn with the item initially either.

0

add an end with a ) in between lines 11 and 12

0

Continues to report the same error.

0

Nope, only do a ')' on Line 11

0

That fixes the error but the gear still won't show up after a death/respawn.

0

Change the entry in admins to {["PlayerName"] = true}, p.Name cannot be converted into a parent/child format for the dictionary.

0

But then how is it supposed to be placed in a backpack/StarterGear of a /specific person/?

0

Just do what I say, nothing has been changed apart from that, like I said, .ChildName can not be accessed by ["ChildName"], because .ChildName is not a string.

0

The fixed and working version of the code is below. Thanks for the effort and help, though.

0

O_o

It's fixed.

Here's the code that makes it work:

local tools = {game.ServerStorage.VEnforcer}
local admins = {Doom10000=true}

game.Players.PlayerAdded:connect(function(p)
if admins[p.Name] then
p.CharacterAdded:connect(function(c)
local backpack = p:WaitForChild("Backpack")
for i,v in ipairs(tools) do
v:Clone().Parent = backpack
end
end)
end
end)

Credit to Warspyking for the code.

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