So here is my script. ServerScript located into the NPC. The NPC takes a nose dive into water as he should based on standard roblox physics, I'm looking for him to float across the top, or at least not nose dive. I would create an animation if needed, I just was hoping to simply insert this script into future NPCs to avoid animating tons of future various NPCs.
I feel like this should be simple, but i've messed around with but didn't manage to get it to work.
function swim() if script.Parent.Humanoid:GetState()==Enum.HumanoidStateType.Swimming then script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Swimming, false) end end script.Parent.Humanoid.StateChanged:Connect(swim)
Delete the animation, but just to be sure, If there is any water near an NPC put a part over the water and add a LocalScript And Put This In
game.players.PlayerAdded:Connect(function() local NPCFoot = script.parent.LeftFoot --Put this in the npc, Not in any parts local WaterBlocker = game.Workspace.WaterBlocker if WaterBlocker.Touched:Connect(function(NPCFoot) then WaterBlocker.CanCollide = true end)
Weirdly, this type of code will only work in a local script. Also,
SetStateEnabled is a toggler, you do not have to use it based on an event, just use it once (it's basically like flipping a switch).
I have tested this inside a local script and it will work just fine. Obviously parent it to a service that will place it to the player like StarterPlayerScripts.
local c = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() local humanoid = c:WaitForChild("Humanoid") humanoid:SetStateEnabled(Enum.HumanoidStateType.Swimming, false)
Even though it is in a local script, the character is controlled by the client and replicates to the server so it would virtually be the same as a server script doing it anyways.