I'm currently trying to make a backpack/inventory system with keypress and clicking but the server script doesn't work with keypress and the local script has the following error:
Local Script Error:
Players.WyattagumsBackUp.PlayerGui.BackpackGUI.Background.a.equipbutton.LocalScript:24: attempt to index upvalue 'itm' (a nil value)
Local Script:
local lab = script.Parent.Parent.label local num = script.Parent.Parent.number local but = script.Parent local pak = script.Parent.Parent.Parent.Backpack local itm = script.Parent.Parent.item.Value local plr = game.Players.LocalPlayer local chr = plr.Character local eqp = script.Parent.Parent.equipped.Value function onClicked() if eqp == false then itm.Parent = chr eqp = true elseif eqp == true then itm.Parent = pak eqp = false end end script.Parent.MouseButton1Down:connect(onClicked) function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.One then if eqp == false then itm.Parent = chr eqp = true elseif eqp == true then itm.Parent = pak eqp = false end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
The server script works perfectly with the clicking but not the keypress, whilst the local script sends out the said error...
Server Script:
local lab = script.Parent.Parent.label local num = script.Parent.Parent.number local but = script.Parent local pak = script.Parent.Parent.Parent.Backpack local itm = script.Parent.Parent.item.Value local plr = script.Parent.Parent.Parent.Parent.Parent.Parent local chr = plr.Character local eqp = script.Parent.Parent.equipped.Value function onClicked() if eqp == false then itm.Parent = chr eqp = true elseif eqp == true then itm.Parent = pak eqp = false end end script.Parent.MouseButton1Down:connect(onClicked) function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.One then if eqp == false then itm.Parent = chr eqp = true elseif eqp == true then itm.Parent = pak eqp = false end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Both scripts are relatively the same, except for the one change which is the "local plr"
Here is an image of the system paths: https://imgur.com/MoSPTkR
If you would require further explanation/information then please do respond to this post on your concerns!
You cannot use a variable directly on a value. Each time, you have to use Instance.Value, while instance is a value, in your case, an object value.
EDIT: Added new script. If this doesn't work, comment.
local lab = script.Parent.Parent.label local num = script.Parent.Parent.number local but = script.Parent local pak = script.Parent.Parent.Parent.Backpack local itm = script.Parent.Parent.item local plr = game.Players.LocalPlayer local chr = plr.Character local eqp = script.Parent.Parent.equipped function onClicked() if eqp.Value == false then itm.Parent = chr eqp.Value = true elseif eqp.Value == true then itm.Parent = pak eqp.Value = false end end script.Parent.MouseButton1Down:connect(onClicked) function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.One then if eqp.Value == false then itm.Parent = chr eqp.Value = true elseif eqp.Value == true then itm.Parent = pak eqp.Value = false end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Hope this helps!
-Maxis_s