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

Why is this KeyDown function not working?

Asked by 8 years ago
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

2 answers

Log in to vote
0
Answered by
StoIid 364 Moderation Voter
8 years ago

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)

Ad
Log in to vote
0
Answered by 8 years ago

You cannot use LocalPlayer in workspace...

Answer this question