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

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

Asked by
Jxemes 75
5 years ago

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

Log in to vote
1
Answered by
green271 635 Moderation Voter
5 years ago

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.

0
Thanks, that helps and I will note this for future references! Jxemes 75 — 5y
Ad

Answer this question