Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I attempted to make a script so you drop tools by pressing "G". Why does it work on Studio only?

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?

1 answer

✓ Accepted answer

The problem here is server to client replication. When FilteringEnabled is on, Scripts 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.

1 comment

0

Thanks, that helps and I will note this for future references!

This discussion is preserved as it was. New answers, comments, and votes are closed.