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

Why is this KeyDown function not working?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function pickup(key)
	print("1")
	if (player.Character.Torso.Position - script.Parent.Position).Magnitude <= 10 then
		print("2")
   		if key == "f" then
		print("3")
       		game.Players[player.Name]:WaitForChild("Hunger").Value = game.Players[player.Name]:WaitForChild("Hunger").Value -5
        	script.Parent:Remove()
    	end
	end
end

mouse.KeyDown:connect(pickup)

This code is in a LocalScript, stored in a part in the Workspace, none of the prints are working? Help? thanks

1 comment

2 answers

I think you should do...

mouse.KeyDown:connect(function(key)
	key = key:lower()
	if key == "f" then

and then put the rest of your code afterwards.

(if it doesn't work, just comment and I'll try again)

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