I was trying to make a script that when a certain person enters that it would equip them with a certain weapon and yes I put the weapon in Lighting, but for some reason it won't work.
1 | Game.Players.PlayerAdded:connect( function (player) |
2 | wait() |
3 | if player.Name = = "red106" then |
4 | Game.Lighting [ "Katana" ] :clone().Parent = player.Backpack |
5 | end |
6 | end ) |
01 | game.Players.PlayerAdded:connect( function (player) --fetching a player |
02 | --player.CharacterAdded:connect(function(c) |
03 | --remove the "--" from above if you want the player to receive the katana every time he/she respawns |
04 | repeat wait() until player.Character --waiting for character |
05 | wait( 2 ) --just in case |
06 | if player.Name = = "red106" then |
07 | game.Lighting [ "Katana" ] :clone().Parent = player.Backpack |
08 | end |
09 | end ) |
10 | --end) --if you deleted the "--" from line 2, then remove the "--" here |
Above should work.
This should work just fine. The only reason it wouldn't work is if you are doing this on Solo Test. Either way, use the "print()" command to see if it goes through both conditions.
Might have been initiated before your player was generated.
1 | Game.Players.PlayerAdded:connect( function (player) |
2 | repeat wait() until Workspace:findFirstChild(player.Name) |
3 | if (player.Name = = "red106" ) then |
4 | Game.Lighting [ "Katana" ] :clone().Parent = player.Backpack |
5 | end |
6 | end ) |
1 | game.Players.PlayerAdded:connect( function (player) |
2 | player.CharacterAdded:connect( function (char) |
3 | if string.lower(char.Name) = = "red106" then |
4 | game.Lighting [ "Katana" ] :clone().Parent = char.Backpack |
5 | end |
6 | end ) |
7 | end ) |
This will add the katana to the characters backpack rather than the players, but it will happen every time the character is created.
Add this as a regular script in the workspace, also use game not Game.
I improved all previous answers and the original code to make it as secure as possible:
01 | local Services = setmetatable ( { } , { __index = function (tab, i) |
02 | return game:GetService(i) or nil |
03 | end } ) |
04 |
05 | WeaponName = "Katana" |
06 | PlayerJoining = "red106" |
07 |
08 | Services.Players.PlayerAdded:connect( function (Player) |
09 | pcall ( function () |
10 | if Player.Name:lower() = = PlayerJoining:lower() and Services.Lighting:FindFirstChild(WeaponName) then |
11 | local Weapon = Services.Lighting [ WeaponName ] |
12 | Weapon.Archivable = true |
13 | local Backpack = Player:WaitForChild( "Backpack" ) |
14 | local NewWeapon = Weapon:Clone() |
15 | NewWeapon.Parent = Backpack |
16 | end |
17 | end ) |
18 | end ) |
So where should this script be in? Workspace, Lightning?
01 | game.Players.PlrAdded:connect( function (plr) |
02 | wait( 1 ) |
03 | if newPlr.Name = = "red106" then |
04 | game.Lighting. [ "Katana" ] :clone().Parent = plr.Backpack |
05 | local kd = "red106" |
06 | if kd = = "red106" then |
07 | Katana:clone() -- Incase you dropped it |
08 | end |
09 | end |
10 | end ) |
MIGHT NOT WORK! MIGHT NOT WORK!