You don't have an end
for the function
or a )
for the (
on line 17. Tab your code correctly.
=
is a completely different thing from ==
.
=
means "set" or "assign" -- it's a command.
==
means "compare?", or "are these the same?" -- it's a question.
if
s and elseif
s need to use ==
, not =
.
==
means "are these the same" -- which includes that they are the same type of thing. Text
is a string (the type of text) while code1
, etc are numbers.
They have to be the same type -- "100" == 100
is false.
The simplest solution would be to change the definition of code1
etc to use strings:
Your code is really repetitive.
The big tree of elseif
s could be changed into a neat little dictionary.
A dictionary turns keys (in this case, it would be the codes) into values (in this case, it would be the weapons).
Defining a dictionary looks like this:
2 | [ "1643543" ] = game.ReplicatedStorage.Weapon 1 , |
3 | [ "3728492" ] = game.ReplicatedStorage.Weapon 2 , |
4 | [ "5638593" ] = game.ReplicatedStorage.Weapon 3 , |
5 | [ "5483759" ] = game.ReplicatedStorage.Weapon 4 , |
6 | [ "4759485" ] = game.ReplicatedStorage.Weapon 5 , |
7 | [ "4739583" ] = game.ReplicatedStorage.Weapon 6 , |
Now you can just check if there is actually a weapon for a given code:
02 | [ "1643543" ] = game.ReplicatedStorage.Weapon 1 , |
03 | [ "3728492" ] = game.ReplicatedStorage.Weapon 2 , |
04 | [ "5638593" ] = game.ReplicatedStorage.Weapon 3 , |
05 | [ "5483759" ] = game.ReplicatedStorage.Weapon 4 , |
06 | [ "4759485" ] = game.ReplicatedStorage.Weapon 5 , |
07 | [ "4739583" ] = game.ReplicatedStorage.Weapon 6 , |
10 | textButton = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton |
11 | textBox = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox |
12 | backPack = game.Players.LocalPlayer.Backpack |
14 | textButton.MouseButton 1 Down:connect( function () |
15 | local weapon = codes [ textBox.Text ] |
18 | weapon:Clone().Parent = backPack |