I had a go at making a swimming script, it's decent....but if the player holds spacebar whilst in the water, they will just fall and end up respawning. Is there a better, more efficient way to do this?

local Server = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local Sea = Workspace:WaitForChild("Sea")

Server.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		local BodyPosition = Instance.new("BodyPosition")
		BodyPosition.MaxForce = Vector3.new(0, 0, 0)
		BodyPosition.Position = Vector3.new(0, 10 ,0)
		BodyPosition.D = 1250
		BodyPosition.P = 10000
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		BodyPosition.Parent = HumanoidRootPart
		local Humanoid = Character:WaitForChild("Humanoid")
		
		Humanoid.Changed:Connect(function()
			wait(1)
			if HumanoidRootPart.Position.Y <= (-1.208) then
					
				BodyPosition.MaxForce = Vector3.new(0, 5000, 0)
				BodyPosition.Position = Vector3.new(0, -1 ,0)
				if Humanoid.Jump == true then
					BodyPosition.Position = Vector3.new(0, 50, 0)
					BodyPosition.MaxForce = Vector3.new(0, 4000, 0)
					wait(1)
					BodyPosition.MaxForce = Vector3.new(0, 0, 0)
					else
				end
			else
				print("no u")
			end
		end)	
	end)

		
		
end)

After the player falls below a certain Y axis position, the bodyposition will activate.

2 comments

0

Are you asking for the BEST way or something to do so that your script is more accurate?

0

welp, tbh you rlly cant, it seems effecient!