You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Create a script that handles hunger. -
What is the issue? Include screenshots / videos if possible!
I handle hunger on the client so I used a remote event to send a specific numbervalue that would vary between different prey, so you would get 5 hunger from a rabbit, 1 from a mouse, etc. The value I put doesn’t seem to pass to OnClientEvent tho, the hunger doesn’t go up and nothing prints, Its like a ghost or something. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Well, I searched up similar stuff but all the issues had to do with stuff like not putting player in FireClient’s parameters, or arguments being nil. I tweaked the script, like making the “hunger” value a variable instead of just a number. Didn’t Work. Its frustrating since I haven’t had much trouble with passing arguments in the past, so Idk what went wrong.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is my “current” script that handles one of the types of prey (rabbit), it handles the health and stuff as well as fires a remote event to the client to add the hunger received.
local PreyPart = script.Parent
local PreyChar = PreyPart.Parent
local PreyHum = PreyChar.Humanoid
local PreyAnim = PreyHum.Animator
local CD = PreyPart.ClickDetector
local FoodAmnt = PreyChar:WaitForChild("FoodAmount")
FoodAmnt.Value = 100
local Eat = game.ReplicatedStorage.Eat
CD.MouseClick:Connect(function(player)
local PlrCharacter = player.Character
local PlrAnimator = PlrCharacter.Humanoid.Animator
local AttackAnim = PlrCharacter.Attack
local DedAnim = script.Ded
local AttackTrack = PlrAnimator:LoadAnimation(AttackAnim)
local DedTrack = PreyAnim:LoadAnimation(DedAnim)
AttackTrack:Play()
if PreyHum.Health > 0 then --if the health is greater than 0 then...
PreyHum:TakeDamage(25)
end
if PreyHum.Health == 0 then
DedTrack:Play()
FoodAmnt.Value = FoodAmnt.Value - 25
Eat:FireClient(player, 5)
end
if FoodAmnt.Value == 0 then
PreyChar:Destroy()
end
end)
And heres the script that answers the remote event when fired…
local player = game:GetService("Players").LocalPlayer
local Char = player.Character or player:WaitForChild("Character")
local hum = Char:WaitForChild("Humanoid")
local Eat = game.ReplicatedStorage:WaitForChild("Eat")
local label = script.Parent
local SurvlStats = Char:WaitForChild("Survival Stats")
local Hunger = SurvlStats:WaitForChild("Hunger")
Hunger.Value = 50
while true do
wait(5)
Hunger.Value = Hunger.Value - 1
label.Text = Hunger.Value.."Hunger"
if Hunger.Value > 100 then
Hunger.Value = 100
elseif Hunger.Value <= 0 then
Hunger.Value = 0
hum:TakeDamage(0.5)
end
end
Eat.OnClientEvent:Connnect(function(Nutrition)
Hunger.Value = Hunger.Value + Nutrition
print(Nutrition)
end)
The Nutrition thing is supposed to be the amount of hunger the player shall receive. Except, nothing passes! Literally nothing! Nothing prints and the hunger doesn’t go up! So, basically, a ghost!
There are no errors in the output so I don’t think its nil, just, doesn’t exist?
If you need more/different info, plz ask and I will provide!
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.