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

KeyDown to Pick up A Gear?

2 answers

First of all you are going to have to make sure the apple is close enough. To do this you have to calculate the distance between the apple and the humanoid. Use the following function =

h = humanoid.Position a = apple.Position

distance = math.sqrt(((h.X - a.X)(h.X - a.X))+((h.Z - a.Z)(h.Z - a.Z)))

Then, make sure that the apple is within range.

range = 5

Put the script below into a local script, then put it into starterGui. Put the gui you want to pop up in the starterGui aswell and disable the gui. When the f key is pressed and the player is in range, the gui will pop up!

player = game.Players.LocalPlayer
mouse = player:GetMouse()
character = game.Workspace:WaitForChild(player.Name)
humanoid = character.Humanoid
gui = player.PlayerGui.AppleGui 				--find the gui you want to pop up
apple = game.Workspace.Apple 				--find the apple, this may not be right
range = 5       								--you can change this
mouse.KeyDown:connect(function(key)
	if key == "f" then
		h = humanoid.Position				
		a = apple.Position
		distance = math.sqrt(((h.X - a.X)*(h.X - a.X))+((h.Z - a.Z)*(h.Z - a.Z)))
		if distance < range then
			gui.Enabled = true
		end
	end
end

Keydown is now a deprecated function meaning it will not work in game.

use UserInputService like this:

game:GetService('UserInputService').InputBegan:connect(function(input, process) -- basically if the player does anything w/ mouse, keyboard or other
	if input.InputType = Enum.InputType.Keyboard then  -- check if it was the keyboard being used
		if input.KeyCode = Enum.KeyCode.F then -- make sure the player pressed F
			-- do ur apple stuff here
		end
	end
end)

basically UserInputService.InputBegan means anytime the person has begun to press the mouse or a keyboard button or other it senses it.

2 comments

0

open that up on notepad to copy properly then do ur stuff.

0

I would say put the gui in lighting then clone it into plr.PlayerGui once F is pressed

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