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

What is happening with my simple "Give a certain player a tool" script? [Solved]

This is just a script inside of workspace. It's working weirdly and I don't know if I did something and I don't notice a simple error or what, but my script is suppose to give a certain player a tool when they enter and if they were to die, they'd get said tool again.

Here's the script:

A = "alphawolvess"
L = "ThisPersonIsASecretSooooyea" -- Not what's actually there, but I wont give out his name in case he prefers not to have it out.
Test = "Player"

game.Players.PlayerAdded:connect(function(Plr)
	Plr.CharacterAdded:connect(function(Char)
		if Char.Name == L or Char.Name == A or Char.Name == Test then
			print("Giving")
			local Copy = game.ServerStorage:FindFirstChild("RedKatana")
			Copy.Parent = Plr.Backpack
		else
			print("Not Giving")
		end
	end)
end)

Yes, I know I can use a generic loop and store the names in a Table. I also know I can use string.lower but the spelling for players is correct. Also, I do know that Player changes from Player1 to Player for some reason, currently (for me) it's Player and I change that if needed. I do get an error about Local Copy being nil

3 comments

0

That means that 'RedKatana' doesn't exist.

0

Minor note: If you're going to assume that Copy is non-nil (line 9), there's no need to use FindFirstChild at all - just do local Copy = game.ServerStorage.RedKatana (and as said below, add a :Copy() somewhere in this area)

0

I know what happened, I didn't clone it so I moved the existing Katana into the first joined allowed player and it was no longer there to use.

2 answers

✓ Accepted answer

I don't know if it's the error or not, but it seems you never actually clone the sword. You index it and attempt to move it, but never physically clone it.

1 comment

0

Oh yea I did it then accidentally removed it and completely forgot about Clone()

You need to actually clone the katana on line 10.

Copy:Clone().Parent = Plr.Backpack

Also you can just use Plr.Name

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