I made a custom water system that works very well. Going up and down whilst swimming, moving horizontally, the sounds, and the lighting all worked in sync at the right times. As I was making another part of the game, and suddenly that system randomly started bugging out for some reason. At first I thought it was lag or simply a weird Roblox Studio bug but it translated to the published version too. I never even changed anything, it just stopped working, 0 errors. Can someone explain to me how this might happen? is there a solution? I have looked on the Dev Forum and have found nothing.
Did you try deleting the other part of the game and then refreshing to see if the script works without that part, or is the script completely broken now?
maybe load up a previous version history?
this wont fix anything, but if it works, at least you know it’s because of something you added/removed.
The 2 things I was working on have no relation to each other. There is no code but itself that references anything in the water system. I refreshed Roblox Studio trying to fix it and that didn’t work.
I did, it didn’t work still. and I don’t really feel like searching through versions, cause idk what all of them are.
Is the system using specific events that could be affected by newly placed parts?
The non working parts are occurring when one of the scripts tries to determine wether the player is in water or not. It uses a :GetPartsInPart() to do this, on heartbeat. There is nothing that would affect the water system other than lag, and it works through heartbeat, which is the speed the game calculates physics, so it should be going the same speed as my frame rate, which should somewhat protect it from lag. I don’t see any possible way new material could affect it.
It sounds like :GetPartsInPart() isn’t picking up overlaps properly, which can happen sometimes in Roblox.
Make sure the water part has CanTouch = true, CanCollide = false, and is anchored.
If this isn’t the issue, I have other possible solutions.
I attempted what you said and it seemed to make it worse. Get parts in part is partially the problem. When I modify the code to less reliably go up and down for swimming, the get parts in part fails every so often and I go out of water for a split second, falling and then being resubmerged. I have 0 idea why I can’t move, and sometimes the get parts in part doesn’t detect when I leave the water until I get way away from the water. It is generally just not working in many random ways, I dont think it is a code issue.
Then, I’d recommend switching to a manual detection system (Region3 or raycast/distance) and fully ditching :GetPartsInPart()
Why? It worked perfectly before. I see no reason to change it when it worked fine. Is there a reason code may break for no cause?
:GetPartsInPart() isn’t always reliable, especially with fast movement or thin parts. It can miss overlaps or lag a frame behind.
Yes but why would I need to change it if it works for my scenario?
Because the script broke by itself; is that not what you said
It was several scripts that broke in the system, not just one. Just so you know, this is all client/character based, and is placed in StarterCharacter, if that helps.
This helps, here’s a couple reasons why it isn’t working:
- Something changed with how the client is loading (like the way the script runs, etc)
- The scripts are running out of sync (which could be the reason why it bugged out)
- If any part of the system relies on something like the camera, humanoid states, or timing via
Heartbeat, even small shifts in how Roblox starts up the character can break stuff
There is a server script that performs get parts in part to check if the player is in the water on heartbeat, and a local script that changes the lighting and other things based off of wether they are in water or not. In the server script it also changes a bool value that is used by the movement scripts, that also shows wether the player is in the water for other script use. I don’t see how it could be out of sync if everything is activated by another, or simple runs by itself checking a value.
Even if the server updates the “in water” value and the client uses it, small delays can happen between them.