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

How to stop dropped items from going through walls? (Solved)

Asked by 4 years ago
Edited 4 years ago

I found a way to solve this issue myself, if you want to know how I've included it at the bottom

I was working on a script that improves the system Roblox uses when you drop an item in game. I did this by making it so that when you drop an item, it goes directly in front of your player, compared what Roblox would normally do. (make it go up in the air and a few studs away) The problem that I have is that items can still go through walls if a player is standing directly next to one. I was wondering if anyone knew a way I could fix this bug or improve upon my code in general. Here's what my script looks like:

script.Parent.Parent.Unequipped:Connect(function()
    local p = game.Players:FindFirstChildWhichIsA("Player") -- singleplayer game

    if script.Parent.Parent.Parent ~= p.Backpack and script.Parent.Parent.Parent ~= p.Character then
        script.Parent.Position = p.Character.Torso.Position + Vector3.new(0, 0, 5)
    end
end)

I also use this method for my backpack limiter. (If a player has more than a certain number of items, it will drop the last item they picked up right in front of them)

Edit: I found a way to fix this issue by putting the tool directly above the players head, (making it almost impossible for it to go out of the map) then making it unclickable by changing the handle name, and making a new handle after two seconds.

script.Parent.Parent.Unequipped:Connect(function()
    local p = game.Players:FindFirstChildWhichIsA("Player")

    if script.Parent.Parent.Parent ~= p.Backpack and script.Parent.Parent.Parent ~= p.Character then
        script.Parent.FirstTime.Value = true
        script.Parent.Position = p.Character.Torso.Position + Vector3.new(0, 2, 0)
        -- make it unequipable
        script.Parent.Name = "Reloading..."
        wait(2)

        -- create new handle
        local newhandle = script.Parent:Clone()
        newhandle.Name = "Handle"
        newhandle.Parent = script.Parent.Parent
        newhandle.Position = script.Parent.Position
        script.Parent:Destroy()
    end
end)

0
This doesn’t always spawn the tool in front of the player does it? ankurbohra 681 — 4y
0
Technically no, it spawns 5 studs from the players torso, not always it's "front" though. NoahsRebels 99 — 4y

Answer this question