I’m trying to make an inventory system and right now I want to make it so that whenever somebody triggers the proximity prompt in a tool, it moves to their backpack and it changes the gui on their toolbox to match the item they picked up. It works fine with 1 player but otherwise it glitches and sometimes the gui updates but sometimes it doesnt. I would try to record a video but my laptop isnt good enough sorry
Local script
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.EmotesMenu, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
local bp = player.Backpack
local ts = game:GetService('TweenService')
local rs = game:GetService('RunService')
local uis = game:GetService('UserInputService')
local cs = game:GetService('CollectionService')
local equipped = false
local lastSlot = 0
local main = script.Parent.Main
local slot1 = main['1']
local slot2 = main['2']
local slot3 = main['3']
local slot4 = main['4']
local slot5 = main['5']
local slot6 = main['6']
local slot7 = main['7']
local slot8 = main['8']
local slot9 = main['9']
local taggedTools = cs:GetTagged('ToolTag')
script.Parent.Server.UpdateUI.OnClientEvent:Connect(function(tool)
for _, slot in pairs(main:GetChildren()) do
if tool:isA('Tool') then
if slot:IsA('ImageButton') then
if slot.ToolName.Text == 'Empty' then
slot.ToolName.Text = tool.Name
if slot.Visible == false and slot.ToolName.Text ~= 'Empty' then
slot.Visible = true
break
end
end
end
end
end
end)
Server script
local uis = game:GetService('UserInputService')
local cs = game:GetService('CollectionService')
local main = script.Parent.Main
local taggedTools = cs:GetTagged('ToolTag')
for _, tool in pairs(taggedTools) do -- adds proximity prompt to any tool in the game if it has the tag
prompt = Instance.new('ProximityPrompt')
prompt.Parent = tool:FindFirstChild('NotAHandle') or tool:WaitForChild('Handle')
prompt.ActionText = 'Pick up'
prompt.ObjectText = tool.Name
prompt.KeyboardKeyCode = Enum.KeyCode.E
prompt.HoldDuration = .25
prompt.Triggered:Connect(function(player)
tool.Parent = player.Backpack
for _, child in pairs(tool:GetChildren()) do
if child.Name == 'NotAHandle' then
child.Name = 'Handle'
child:WaitForChild('ProximityPrompt').Enabled = false
script.UpdateUI:FireClient(player, tool)
break
end
end
end)
end
Ive tried moving it all to a server script, moving it all to a local script, and I have re written it 3 times but it’s always buggy