Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't my function giving all players a gear? [Mostly Solved]

I am making a Minigame like thing, and I am quickly making a test so I can adapt with it. So, I went and made a function that gave all players a sword, and I was going to reverse enginner it to make it removed (im gonna have to figure that out my self), But it wont work.

This is the code I did.

function givesword()
	local player = game.Players:GetPlayers()
	local tool = script.ClassicSword:Clone()
	tool.Parent = player.Backpack
end

If anyone knows what I am doing wrong, that will be grateful. Thanks. :P

Details: The gear is inside the script which runs the main game. The location of the script is inside ServerScriptService. Everything else works, except for giving all players the gear.

Update: So, I got the adding the sword part done, I am just having issue with removing the sword from the players.

function removesword()
	local players = game.Players:GetPlayers()
	
	for i, player in pairs(players) do
		player.Backpack.ClassicSword:Destroy()
	end
end

This was my attempt. Ended up breaking the entire cycle. oof.

7 comments

0

Instead of using Backpack,try using StarterPack

0

It doesn't work sadly. I think it may have to do with the local 'player', but I am not sure. :P

0

Do not use StarterPack... the issue is that player is a table.

0

Iterate table 'player' and give each index a new copy of 'tool'.

0

if he places the tools in StarterPack people spectating the game will have the tool as well

0

uhh, i'm an ok scripter, but i dont really understand scripter talk yet. is it alright if someone can explain what is being talked about in a simpler way? thanks. :P

0

Sorry,my mistake

1 answer

✓ Accepted answer

regarding SummerEquionox's comment Iterate table 'player' and give each index a new copy of 'tool'

function givesword()
	local players = game.Players:GetPlayers() -- GetPlayers() returns a table of players. ex: {player1, player2, player3}

	-- iterate or loop through the players table:

	for i, player in pairs(players) do 
		local tool = script.ClassicSword:Clone()
		tool.Parent = player.Backpack
	end
end

2 comments

0

Seems really good! I just got to find out how to iterate/loop through the table. :P

0

Seems like it works! Now I have to figure out how to reverse engineer this script...

This discussion is preserved as it was. New answers, comments, and votes are closed.