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

3 comments

0

LocalScripts don't work in the workspace

0

They work in replicatedFirst,StaterPlayerScripts,StarterPack,StarterGui and the player object'

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