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

How to modify it so that the tool is given again, after resetting/respawning?

Asked by 4 years ago
local plr = game:GetService("Players")


game.Players.PlayerAdded:Connect(function(plr)
    local character = game.Workspace:WaitForChild(plr.Name)
      if plr.Name == "aprilsfooled" then
        print (plr.Name .. " , has spawned")
     local t = game.ServerStorage.Tools.Keycard:Clone()
       t.Parent = plr.Backpack

end
end)

2 answers

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

CharacterAdded I believe fires on a respawn and on join.

Ex.

local Name = "aprilsfooled"

game.Players[Name].CharacterAdded:Connect(function()
    -- your code --
end)
0
Just want to know that you don’t have to do game.Players[plr.Name] when par has already been given to you. Also, there is no need to check for the player’s name, the connection is only for the given player. ankurbohra 681 — 4y
0
@ankurbohra04 That is correct, I don't know what I was thinking. I'll fix the code. Benbebop 1049 — 4y
0
@Benbebop aprilsfooled is not a valid member of Players aprilsfooled 29 — 4y
0
@aprilsfooled make sure that the name is exacly the same as your roblox name. If that doesnt work, run a test and look in the players then copy the name of your client. Paste it there and try it again. Benbebop 1049 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(plr)

    plr.CharacterAdded:Connect(function(character)

        if plr.Name == "yourinvolvedplayer" then

             print (plr.Name .. " , has spawned")

                 local t = game.ServerStorage.Tools.Keycard:Clone()
                 t.Parent = plr.Backpack
        end
    end)

end)    

I got it fixed. Thanks for the help though.

Answer this question