game.Workspace.WATER.Touched:connect(function(hit) wait(2) hit = game.Players:GetPlayerFromCharacter(hit.Parent) game.Players:FindFirstChild(hit).Oxygen.Value = game.Players:FindFirstChild(hit).Oxygen.Value - 2 end)
Basically the player has a numbervalue called oxygen and I want to make it so while the player is touching water the value has 2 subtracted every 2 seconds but this script doesn't work the error I get is 16:34:25.714 - Workspace.WATER.Script:3: attempt to index a nil value
Your "hit" variable was already classified by the event. Basically, you didn't need to set a hit variable after the player touches the "WATER", as the event already found the part that hit it.
game.Workspace.WATER.Touched:connect(function(hit) wait(2) local player = hit.Parent player.Oxygen.Value = player.Oxygen.Value - 2 end)
Pretty sure that should work