Hello! I can't wrap my head around this but I tried to make a hunger system. Everything works well but I cannot make a Part bring food when clicked..
Problem code:
local debounce = false
local ClickDetect = script.Parent.ClickDetector
local player = game.Players.LocalPlayer
script.Parent.ClickDetector.MouseClick:Connect(function()
if debounce == false then
debounce = true
local Hunger = player.leaderstats.Hunger
player.leaderstats.Hunger.Value += 1
script.Parent.Transparency = 1 -- Makes Block Invisible
ClickDetect.MaxActivationDistance = 0
wait(600) -- Changes how long the block is not visible
script.Parent.Transparency = 0 -- Makes block visible again
ClickDetect.MaxActivationDistance = 10
debounce = false
end
end)
leaderstats code:
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
local Hunger = Instance.new("IntValue")
Hunger.Name = "Hunger"
Hunger.Value = 100
Hunger.Parent = leaderstats
local Thirst = Instance.new("IntValue")
Thirst.Name = "Thirst"
Thirst.Value = 100
Thirst.Parent = leaderstats
end
-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event
Players.PlayerAdded:Connect(leaderboardSetup)
Problem is: I cannot increase the Hunger IntValue.. Can anybody help?

4 comments
It is already a Server-Side Script.
I Fixed Up The Code For The Server Side Script.
WAit I didn't look at the (function(player) xd yep this is the answer! I made a more clean version, too, where you don't need the (Local Hunger)
Also You Can Get The Player From A Server Side Script. Cause It Doesnt No Who To Direct It To