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

How do I pick up the pizza with a click?

I am making a game and I got a pizza delivery system model. To pick up the pizza I have to press E, I want it so when you pick up the pizza, you click on it instead of having to press E.


local pzname = script.Parent.PizzaName
local player = game.Players.LocalPlayer
local char = player.Character
local humanoid = char:WaitForChild('Humanoid')
-- [KNEEL]
function onKeyPress(inputObject, gameProcessedEvent)
    if(gameProcessedEvent == true) then return end
     if inputObject.KeyCode == Enum.KeyCode.E and script.Parent.PizzaSelected.Value == 'true' and script.Parent.HasPizza.Value == 'false' then
	    game.ReplicatedStorage.Pizza.DeliverBox:FireServer()
	    script.Parent.HasPizza.Value = 'true'
	     workspace:FindFirstChild("Pizzas"):FindFirstChild(pzname.Value).Transparency = 1
	---[Local sided for you want the player only to see the change but others see you delivering it]
	      workspace:FindFirstChild("Pizzas"):FindFirstChild(pzname.Value).ClickDetector.MaxActivationDistance = 0
	     local chosen = math.random(1,2) -- [TOTAL Amount of NPCS to deliver too]
	if chosen == 1 then
		 local npcname = 'Delivery1' --- Change name per npc
		 game.ReplicatedStorage.Pizza.NPCSpawn:FireServer(npcname)
		  script.Parent.Parent.Marker.Enabled = true
		wait(1)
	      local point = game.ReplicatedStorage.Markers.Pos
	     
	      point.Position = workspace.DeliPerson.Torso.Position -- Change name "DeliPerson" to the npc model name 
	 
	elseif chosen == 2 then
		  local npcname = 'Delivery2' --- Change name per npc
		  game.ReplicatedStorage.Pizza.NPCSpawn:FireServer(npcname)
		  script.Parent.Parent.Marker.Enabled = true
		wait(1)
	      local point = game.ReplicatedStorage.Markers.Pos

	      point.Position = workspace.DeliPerson2.Torso.Position -- Change name "DeliPerson" to the npc model name 
	      
	  
	end
          wait(10) -- Cooldown until pizza respawns
	      workspace:FindFirstChild("Pizzas"):FindFirstChild(pzname.Value).ClickDetector.MaxActivationDistance = 10
	         workspace:FindFirstChild("Pizzas"):FindFirstChild(pzname.Value).Transparency = 0
     else	
    end
end

game:GetService("UserInputService").InputBegan:Connect(onKeyPress)

https://www.roblox.com/library/4472393205/PokePizzaDeliverySystem

1 answer

Use ClickDetectors. Put one in the pizza object. Then add a script. This would be done like so:


local clickDetector = workspace.Pizza --Change to the actual pizza.
 
function onMouseClick()
	print("Clicked.”)
        --Insert pickup code here
end
 
clickDetector.MouseClick:connect(onMouseClick)

I wrote this from my head, so there is the possibility of an error. Adapt this to your needs.

Merry Christmas! :)

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