Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
0
Answered by
yurhomi10 192
8 years ago
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

0
Sorry, tool still spawns initially but is lost with death/respawn. Doom10000 5 — 8y
0
Try panthers, I forgot to add a characterAdded function. yurhomi10 192 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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.

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. Doom10000 5 — 8y
0
add an end with a ) in between lines 11 and 12 yurhomi10 192 — 8y
0
Continues to report the same error. Doom10000 5 — 8y
0
Nope, only do a ')' on Line 11 TheDeadlyPanther 2460 — 8y
View all comments (6 more)
0
That fixes the error but the gear still won't show up after a death/respawn. Doom10000 5 — 8y
0
Change the entry in admins to {["PlayerName"] = true}, p.Name cannot be converted into a parent/child format for the dictionary. TheDeadlyPanther 2460 — 8y
0
But then how is it supposed to be placed in a backpack/StarterGear of a /specific person/? Doom10000 5 — 8y
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. TheDeadlyPanther 2460 — 8y
0
The fixed and working version of the code is below. Thanks for the effort and help, though. Doom10000 5 — 8y
0
O_o TheDeadlyPanther 2460 — 8y
Log in to vote
0
Answered by 8 years ago

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.

Answer this question