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)
I editted your script to be a Server Script, hope this helps
local block = game.Workspace:FindFirstChild("Water") wait() local debounce = false block.Touched:connect(function(p) if p.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(p.Parent.Name) then local character = p.Parent local thirst = game.Players:FindFirstChild(p.Parent.Name):FindFirstChild("ThirstVal") 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 end)
This will work with all parts called "Water" (You can change this on the first line...)
local block = "Water" wait() local debounce = false local thirst = game.Players.LocalPlayer:WaitForChild("ThirstVal") repeat wait() until game.Players.LocalPlayer.Character local character = game.Players.LocalPlayer.Character game.Players.LocalPlayer.Character.HumanoidRootPart.Touched:connect(function(p) if p.Name == block then thirst.Value = thirst.Value + 10 if thirst.Value > 100 then thirst.Value = 100 end end end)
Good Luck with your games