I have been trying to make an pickup script where when an item is picked up it automatically goes into the first empty slot. There is a script inside of the group of slots that checks to see if something is in the slots and if there is then it will set the value that is inside of the slot to true. If it is true then it will switch another number value named next slot to the next empty slot
This is that script:
local player = game.Players.LocalPlayer
local character = player.Character
local hum = character:WaitForChild("Humanoid")
while true do
if script.Parent["slot1"].hasitem.Value == false then
character.weapons.nextslot.Value = 1
elseif script.Parent["slot2"].hasitem.value == false then
character.weapons.nextslot.Value = 2
elseif script.Parent["slot3"].hasitem.value == false then
character.weapons.nextslot.Value = 3
elseif script.Parent["slot4"].hasitem.value == false then
character.weapons.nextslot.Value = 4
elseif script.Parent["slot5"].hasitem.value == false then
character.weapons.nextslot.Value = 5
end
wait()
end
Another script that is inside of the pickup GUI is there so that when e is pressed and the mouse is over an active part, it sets the variable isempty to true so that when another weapon is picked up it goes into the next slot.
Here is that script:
local RunService = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local character = Player.Character
local ActiveParts = workspace:WaitForChild("Weapons")
local
nextslot = character:WaitForChild("weapons").nextslot.Value
local Tag = script.Parent
RunService.RenderStepped:connect(function()
local Target = Mouse.Target
if Target and ActiveParts:IsAncestorOf(Target) then
Tag.Visible = true
uis.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
local children = workspace.Weapons:GetChildren()
for i, child in ipairs(children) do
Target.Parent.Parent = character.weapons.backpack:WaitForChild("slot"..nextslot)
script.Parent.Parent.Parent.Items:WaitForChild("slot"..nextslot).hasitem.Value = true
print(nextslot)
end
else
Tag.Visible = false
end
end)
end
Tag.Position = UDim2.new(0,Mouse.X-Tag.AbsoluteSize.X,0,Mouse.Y-Tag.AbsoluteSize.Y)
end)
This is the script where the thing is not working. The actual value in the next slot is updating, directory on line 9, but in the script it is not changing for some odd reason which I am not aware of. I tried seeing if this was the case by adding a print next slot which you can see on line 27 and this is the problem because when I press e on the item that has spawned it puts the item into slot 1 and still prints 1 and then I go to the other spawned weapon and press e on it and it still puts into slot 1 and prints 1. If anyone could help me with this then that would be appreciated.

3 comments
Don’t reference .Value in a variable.
Why? How would I access the variable?
Ok nevermind It worked thank you.