This script makes a local players thirst bar go up when they touch water. However, if there are more then one brick with the same name, it does not work, does anyone know how to get around this and make it work?
-- Localscript
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character
local block = game.Workspace:FindFirstChild("Water")
wait()
local thirst = game.Players.LocalPlayer.ThirstVal
local debounce = false
block.Touched:connect(function(p)
if debounce then return end
debounce = true
local humanoid = p.Parent:FindFirstChild'Humanoid'
if humanoid and p.Parent == character then
thirst.Value = thirst.Value + 10
if thirst.Value > 100 then
thirst.Value = 100
end
end
debounce = false
end)
This is another take on it that doesn't work...
-- Localscript
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local character = player.Character
local block = game.Workspace:GetChildren()
wait()
local thirst = game.Players.LocalPlayer.ThirstVal
local debounce = false
player.Character.HumanoidRootPart.Touched:connect(function(p)
if block.Name == ("Water")
then
if debounce then return end
debounce = true
local humanoid = p.Parent:FindFirstChild'Humanoid'
if humanoid and p.Parent == character then
thirst.Value = thirst.Value + 10
if thirst.Value > 100 then
thirst.Value = 100
end
else
print("a")
end
debounce = false
end
end)

6 comments
Use a regular script then use the Touched function. Put the script in each water part.
I would but it does not work, I tested it
what script would you put in a block, maybe I missed something
use a local script like you are now, but instead of detecting if the water part was touched, how about trying to see if the character's "HumanoidRootPart" was touched. Then when it was, check to see if the name of the part being touched was named "Water" by doing something like this, "if p.Name == "Water" then"
here is what I got :
check my post I updated it