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.
Game.Players.PlayerAdded:connect(function(player) wait() if player.Name == "red106" then Game.Lighting["Katana"]:clone().Parent = player.Backpack end end)
game.Players.PlayerAdded:connect(function(player) --fetching a player --player.CharacterAdded:connect(function(c) --remove the "--" from above if you want the player to receive the katana every time he/she respawns repeat wait() until player.Character --waiting for character wait(2) --just in case if player.Name == "red106" then game.Lighting["Katana"]:clone().Parent = player.Backpack end end) --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.
Game.Players.PlayerAdded:connect(function(player) repeat wait() until Workspace:findFirstChild(player.Name) if (player.Name == "red106") then Game.Lighting["Katana"]:clone().Parent = player.Backpack end end)
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(char) if string.lower(char.Name) == "red106" then game.Lighting["Katana"]:clone().Parent = char.Backpack end end) 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:
local Services = setmetatable({}, {__index = function(tab, i) return game:GetService(i) or nil end}) WeaponName = "Katana" PlayerJoining = "red106" Services.Players.PlayerAdded:connect(function(Player) pcall(function() if Player.Name:lower() == PlayerJoining:lower() and Services.Lighting:FindFirstChild(WeaponName) then local Weapon = Services.Lighting[WeaponName] Weapon.Archivable = true local Backpack = Player:WaitForChild("Backpack") local NewWeapon = Weapon:Clone() NewWeapon.Parent = Backpack end end) end)
So where should this script be in? Workspace, Lightning?
game.Players.PlrAdded:connect(function(plr) wait(1) if newPlr.Name == "red106" then game.Lighting.["Katana"]:clone().Parent = plr.Backpack local kd = "red106" if kd =="red106" then Katana:clone() -- Incase you dropped it end end end)
MIGHT NOT WORK! MIGHT NOT WORK!