Recently I have been working on a custom pick up method. I used a free model as a template then edited the scripts to suit my needs (pls don't hate xddd). You would go up to the weapon, press Q and the weapon would disappear and you would find it in your inventory. When I go on Studio Test all is fine but once I test a server then I can only see the gui to pick up the item and when I press Q nothing happens. I also made it so the GUI disappears after 3 seconds. After the 3 seconds are gone, the gui disappears and never comes back once i touch the hitbox again.... Does it have to do with Filtering Enabled? How can I fix this issue?
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() tool = script.Parent.ToolData k = script.Parent.HotkeyData buttonPressed = false function Press(key) if (key == k.Value) and game.ServerStorage:FindFirstChild(tool.Value) ~= nil then if Player.Backpack:FindFirstChild(tool.Value) == nil and Player.Character:FindFirstChild(tool.Value) == nil then local weapon = game.ServerStorage:FindFirstChild(tool.Value):clone() weapon.Parent = Player.Backpack repeat Player.PlayerGui:FindFirstChild("HotKeyGuiThing"):remove() until Player.PlayerGui:FindFirstChild("HotKeyGuiThing") == nil workspace["Weapon Crate"]:remove() end end end Mouse.KeyDown:connect(Press) wait (2) repeat Player.PlayerGui:FindFirstChild("HotKeyGuiThing"):remove() until Player.PlayerGui:FindFirstChild("HotKeyGuiThing") == nil
This is a problem with FilteringEnabled yes. A script cannot listen to the mouse.KeyDown event, because it runs on the server. A localscript cannot clone items from serverstorage and give them to a player:
You need to separate these two things by listening to the mousclick in a localscript, firing a remoteEvent on the server, and listening to that event by a script.
Keep in mind that scripts should not be put in the startergui and localscripts should not be put in workspace.
Also I recommend using Destroy() over Remove() (remove is also deprecated)
Finally to interact with things in workspace, it's better to check if this item exists before applying functions to it:
if workspace:FindFirstChild("Weapon Crate") then workspace["Weapon Crate"]:Destroy() end
Good luck!