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 5 years ago
01local plr = game:GetService("Players")
02 
03 
04game.Players.PlayerAdded:Connect(function(plr)
05    local character = game.Workspace:WaitForChild(plr.Name)
06      if plr.Name == "aprilsfooled" then
07        print (plr.Name .. " , has spawned")
08     local t = game.ServerStorage.Tools.Keycard:Clone()
09       t.Parent = plr.Backpack
10 
11end
12end)

2 answers

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

CharacterAdded I believe fires on a respawn and on join.

Ex.

1local Name = "aprilsfooled"
2 
3game.Players[Name].CharacterAdded:Connect(function()
4    -- your code --
5end)
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 — 5y
0
@ankurbohra04 That is correct, I don't know what I was thinking. I'll fix the code. Benbebop 1049 — 5y
0
@Benbebop aprilsfooled is not a valid member of Players aprilsfooled 29 — 5y
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 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
01local Players = game:GetService("Players")
02 
03game.Players.PlayerAdded:Connect(function(plr)
04 
05    plr.CharacterAdded:Connect(function(character)
06 
07        if plr.Name == "yourinvolvedplayer" then
08 
09             print (plr.Name .. " , has spawned")
10 
11                 local t = game.ServerStorage.Tools.Keycard:Clone()
12                 t.Parent = plr.Backpack
13        end
14    end)
15 
16end)   

I got it fixed. Thanks for the help though.

Answer this question