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

Is there any way for a mobile Roblox user to grab and drop a part?

I'm trying to make a way for players using mobile to have the ability to also grab a part, as currently it doesn't work on mobile..

Some sort of script that would maybe put it in their hand ontouch, then once they touch it again, it drops it.

If anyone knows how this could be done, that would be great.

2 answers

So when the user picks up a part on mobile, maybe set the camera type to Scriptable then when they drop the part make it Custom so that it freezes the camera when an object is selected.

Yes!

To start off, let's make a mobile button that prints "Clicked" and has all the essential variables/properties.

Code:

local ContextActionService = game:GetService("ContextActionService")
 
local function Drop(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("Clicked")
	end
end
 
ContextActionService:BindAction("Interact", collectTreasure, true, Enum.KeyCode.T, Enum.KeyCode.ButtonR1)
ContextActionService:SetPosition("Interact", UDim2.new(1, -70, 0, 10)) -- position
ContextActionService:SetImage("Interact", "rbxassetid://0123456789") -- image

Okay, once we do that, let's make it detect if a player is holding an item and make it drop.



function CHECK_TOOL(character)
    for _, v in pairs(character:GetChildren()) do -- all children in character
        if v:IsA("Tool") then -- if is a tool
            print("tool found!") -- print
            return v
        end
    end
end

Now, let's combine the codes.

local ContextActionService = game:GetService("ContextActionService")

local function Drop(actionName, inputState, inputObject)
    if inputState == Enum.UserInputState.Begin then
        print("Clicked")
        local Character = game.Players.LocalPlayer.Character

        function CHECK_TOOL(character)
            for _, v in pairs(character:GetChildren()) do
                if v:IsA("Tool") then
                    print("tool found!")
                    return v
                end
            end
        end
    end
end
local v = Drop(game.Players.LocalPlayer.Character)
v.Parent = workspace
v.Position = character.Position

ContextActionService:BindAction("Interact", collectTreasure, true, Enum.KeyCode.T, Enum.KeyCode.ButtonR1)
ContextActionService:SetPosition("Interact", UDim2.new(1, -70, 0, 10))
ContextActionService:SetImage("Interact", "rbxassetid://0123456789")


btw, I didn't script to pick up because when you hit the tool, (step on) it automatically picks it up

9 comments

0

don't give the script

0

why?

0

bruh whyd you downvote for sending a code

0

Thanks, I'll test it out tomorrow and experiment. :)

0

if it works please upvote and accept answer ty!

0

if it works please upvote and accept answer ty!

0

Don’t worry I will upvote it, idky leamir downvoted it

0

same

0

ty

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