Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My custom pick-up script only works in Roblox Studio. When I go in-game, why is it not working?

Asked by 6 years ago

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
0
Oh, and this is just a script in the GUI. The hitbox script just puts it in the player's inventory sahadeed 87 — 6y

1 answer

Log in to vote
1
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago

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!

1
Fast response! Thank you for your help! sahadeed 87 — 6y
Ad

Answer this question