How do I make a water drinking system?

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to make a drinking system similar to Sapien.
    When standing on water, if you press a button an animation loads then your water bar goes up. I already have a thirst system and only need the drinking system, but i’m not sure how to create it.

  2. What is the issue? Include screenshots / videos if possible!
    I am unsure how to create a drinking system, and whenever I try it doesn’t work, and has no errors.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried using a very simple system I made. A function checked that the player is touching a part in the water, and if it was, it set a value to 1. A function checked if the value was 1, and if it is then if the player presses V then a animation loads. Nothing loads and I’m not sure how to fix it.

(It was poorly made.)

(I’m not asking for an entire script, just an outline/idea of how to do it.)

1 Like

This is what I would do.

  1. When player presses button, check if the player is standing on the water, however you do it.
  2. If the player is standing on water, if so then send a remote to the server to check if the player does need water, so his bar isn’t filled.
  3. When the server checks and if its not filled, then send a remote back to the client to do the animation and change the water bar gui to fill it, but in the server make sure you actually do increase the water level as well.

This outline should be pretty simple, you could do a bit more to make user experience better, but I think it should be fine.

Also, try testing all of these in individual part to make sure each parts do work, so try 1 first and make sure it does work with like print statements or something and try the rest of them as well.

1 Like

So I would create a server script with something like this:

local Plr = game.Players.LocalPlayer -- i am aware this is for localscripts, 
--but i'm not sure how to define player besides in a function.
local ThirstVal = Plr:WaitForChild("ThirstVal") 

game.workspace.WaterFolder.WaterPart.Touched:Connect(function(hit)
elseif hit.parent.ThirstVal < 100 then
       game.replicatedstorage.RemoteEvent:Fire()
elseif hit.parent.ThirstVal > 100 then
ThirstVal = 100
       end
end)

Then, I would use a localscript in replicated storage, and check it was touched by checking the RemoteEvent to load the animation and fill the bar.

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
	local Plr = game.Players.LocalPlayer
	local ThirstVal = Plr:WaitForChild("ThirstVal") 
	--animation part, still unsure how to code localscript animations non-depreciated(working on it)
	print("RemoteEvent Activated") --just to see if it works for the first time.
if ThirstVal.Value < 100 then
	ThirstVal.Value = ThirstVal.Value + 40
	game.Workspace.Sounds.LeafEating:Play()
elseif ThirstVal.Value > 100 then
	ThirstVal.Value = 100
	end
end)

I haven’t tested this yet and just coded it quickly, just checking this is what you meant.

This is not exactly what I had in mind, but did you get it to work?

I got it to work fine and I’m just trying to stop it from firing multiple times now, thank you!

Heres a roblox article for a debounce, which should help you with your multiple firing of remotes, I assume. The dev forum should also have a lot of examples and tutorials on it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.