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

Why is UserInputService not working?

Asked by 8 years ago
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(input)
    if (player.Character.Torso.Position - script.Parent.Position).Magnitude <= 10 then
        if input.KeyCode == Enum.KeyCode.F then
            game.Players[player.Name]:WaitForChild("Hunger").Value = game.Players[player.Name]:WaitForChild("Hunger").Value -5
            script.Parent:Remove()
        end
    end
end)

From my last 2 questions, I got some wiki links, but I am still not that good of knowing how to do these.
Details: -This code is stored in a LocalScript -The LocalScript is in a part in the workspace -This script doesn't work? -I want the player to be within a range of 10 of the item, and if F is pressed, it removes 5 from your value and removes the parent.

Help? Thanks

0
LocalScripts don't work in the workspace theCJarmy7 1293 — 8y
0
They work in replicatedFirst,StaterPlayerScripts,StarterPack,StarterGui and the player object' theCJarmy7 1293 — 8y
0
but I am going to have multiple of the same item and named the same, how will it know which one the player is near thehybrid576 294 — 8y

Answer this question