Back at it again with the questions to help my player 'needs' scripting....
So this one is a bit more simple.
I have needs set up in a gui... Here is an example of a script I have which decreases your need to use the bathroom once you hit a block (100 = full need 0= no need)
script.Parent.Touched:connect(function(part)
local plr = game.Players:GetPlayerFromCharacter(part.Parent)
if plr then
local hunger=plr:FindFirstChild("PlayerGui").Bladder.Hunger
hunger.Value = hunger.Value - 2
end
end)
This works perfectly (ignore hunger its just... a thing i refuse to rename.)
Now, is there a way for this to do the same thing, however have a script running that basically does as follows
Every second it: (while wait(1) do)
Tests to see if another player is within a... 20 unit distance from the player
if that says true, it increases the value by 2 every second for the social need meaning the script would be:
local hunger=plr:FindFirstChild("PlayerGui").**Social**.Hunger
Thank you!
PS: I don't know how to mark answers as correct so please tell me how to so I can give you credit!!
Edit: Script that is close to, but not working.
-- Local Script in StarterPack or something
-- Variables
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local Torso = char:WaitForChild("Torso")
local Social = game.Players.LocalPlayer.PlayerGui.Social.Hunger-- This is the correct location.
local MaxDistance = 20 -- Distance before social goes up
-- Function
local function CheckPlayers()
for i,player in pairs(game.Players:GetPlayers()) do
if v ~= plr then
local otherTorso = player.Character.Torso
local Distance = (Torso.Position-otherTorso.Position).Magnitude
if (Distance <= MaxDistance) then
return true
end
end
end
return false
end
-- Main Loop
while wait(1) do
if CheckPlayers() then
print("True") -- output is currently only spamming this
Social.Value = Social.Value -2 -- This has to be minus instead of plus b/c we are taking the need of social away by being closer to other players.
else
print("False") -- never seen this in output yet.
end
end

2 comments
I just tested the script only to notice I put v instead of player on line 13. I edited the script, tested it, and I know it works now. Sorry about the typos.
Yup, working now thank you :)