How can I make this more efficient?
So basically I want the player's walk speed to change whenever it is in the Terrain water. What I made bellow works, but I'd like it to be more efficient, and only change when the player is in/out of the water. I don't really know how to go about doing so, and I would really appreciate some help <3
01 | game.Players.PlayerAdded:connect( function (Player) |
02 | Player.CharacterAdded:connect( function (char) |
03 | local humanoid = char:WaitForChild( "Humanoid" ) |
06 | humanoid.Swimming:connect( function (swim) |
07 | if swim > 0 then drown = true |
08 | elseif swim < 1 then drown = false |
13 | if drown then humanoid.WalkSpeed = 5 |
15 | local found = game.Workspace:FindFirstChild(humanoid.Parent.Name.. "'s_folder" ) |
17 | humanoid.WalkSpeed = found.Speed.Value |
Happy murica day!