I didn't want to make my weapon drop by backspace, because the player would still be holding the tool (I welded the tool). So I made a script and placed it in StarterPlayer>StarterCharacterScripts and this is what the code looks like.
local character = script.Parent function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.G then for _, child in ipairs(character:GetChildren()) do if child:IsA("Tool") then child.Parent = workspace.Drops child.Handle.CFrame = CFrame.new(child.Handle.CFrame.X, child.Handle.CFrame.Y + 5, child.Handle.CFrame.Z) end end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
So whenever I press G while holding a tool, it should get everything inside the Character, find any tools inside the character, and if there is one, it should change the parent to workspace.Drops which is a folder, and move the tool 5 studs above the player. Like I said, it works on Studio, but not on the ROBLOX Client. Any things I could change in this script? Or I did it completely wrong?
The problem here is server to client replication. When FilteringEnabled is on, Script
s will only run in the Workspace
or ServerScriptService
(and any of their descendants). This is why it will only work in studio, as these restrictions are ignored during testing.
Copy paste your code into a localscript then try it.