So basically I have a system when the round starts it picks a character for the player and inside the Humanoid, it puts a string value called CharName, and the value is the character’s name.
How would I make an item go to a specific character’s backpack when they spawn in?
local players = game.Players:GetPlayers()
local SelectedPlayer = players[math.random(1, #players)]
--give the player the item
local item = --item here
item.Parent = SelectedPlayer.Backpack
local item = --item here
for _, p in pairs(game.Players:GetPlayers()) do
if p.Character.Humanoid:FindFirstChild("CharName") ~= nil then
local cloneitem = item:Clone()
cloneitem.Parent = p.Backpack
end
end
Basically, it loops through all the players in the server, then it checks if “CharName” is not nil (“nil” means that it does not exist or does not have any value). If so, then it clones the item to their Backpack
Well you said before that the selected player gets a StringValue named “CharName” put into their Humanoid, so I check if it exists in their humanoid before I clone the item to their backpack
no but how would I specify in the script what the Character’s name in the string value is? The value becomes their name when the round starts. Only specific characters would get these special items.
--switched 'p' to 'player' to make it more clear
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character.Humanoid:FindFirstChild("CharName") ~= nil then
player.Character.Humanoid.CharName.Value = player.Name
end
end
Blockquotefor local item = game.ServerStorage.YouLikeThat --item here
local Fabio = game.Workspace.p
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character.Humanoid:FindFirstChild(“CharName”) ~= nil then
player.Character.Humanoid.CharName.Value = player.Fabio
local cloneitem = item:Clone()
cloneitem.Parent = player.Backpack
end
end
--FULL CODE
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character.Humanoid:FindFirstChild("CharName") ~= nil then
player.Character.Humanoid.CharName.Value = player.Name
local cloneitem = item:Clone()
cloneitem.Parent = player.Backpack
end
end